Add bswap, rotl, and rotr nodes
[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<1, 2, [SDTCisVT<0, FlagVT>, SDTCisSameAs<1, 2>]>;
25
26 def SDTX86Cmov    : SDTypeProfile<1, 4,
27                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
28                                    SDTCisVT<3, i8>, SDTCisVT<4, FlagVT>]>;
29
30 def SDTX86BrCond  : SDTypeProfile<0, 3,
31                                   [SDTCisVT<0, OtherVT>,
32                                    SDTCisVT<1, i8>, SDTCisVT<2, FlagVT>]>;
33
34 def SDTX86SetCC   : SDTypeProfile<1, 2,
35                                   [SDTCisVT<0, i8>, SDTCisVT<1, i8>,
36                                    SDTCisVT<2, FlagVT>]>;
37
38 def SDTX86Ret     : SDTypeProfile<0, 1, [SDTCisVT<0, i16>]>;
39
40 def SDT_X86CallSeqStart : SDTypeProfile<0, 1, [ SDTCisVT<0, i32> ]>;
41 def SDT_X86CallSeqEnd   : SDTypeProfile<0, 2, [ SDTCisVT<0, i32>,
42                                                 SDTCisVT<1, i32> ]>;
43
44 def SDT_X86Call   : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
45
46 def SDTX86FpGet   : SDTypeProfile<1, 0, [SDTCisVT<0, f64>]>;
47 def SDTX86FpSet   : SDTypeProfile<0, 1, [SDTCisFP<0>]>;
48
49 def SDTX86Fld     : SDTypeProfile<1, 2, [SDTCisVT<0, f64>,
50                                          SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>]>;
51 def SDTX86Fst     : SDTypeProfile<0, 3, [SDTCisFP<0>,
52                                          SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>]>;
53 def SDTX86Fild64m : SDTypeProfile<1, 1, [SDTCisVT<0, f64>, SDTCisPtrTy<1>]>;
54
55 def SDTX86RdTsc   : SDTypeProfile<0, 0, []>;
56
57 def X86addflag : SDNode<"X86ISD::ADD_FLAG", SDTIntBinOp ,
58                         [SDNPCommutative, SDNPAssociative, SDNPOutFlag]>;
59 def X86subflag : SDNode<"X86ISD::SUB_FLAG", SDTIntBinOp,
60                         [SDNPOutFlag]>;
61 def X86adc     : SDNode<"X86ISD::ADC" ,     SDTIntBinOp ,
62                         [SDNPCommutative, SDNPAssociative]>;
63 def X86sbb     : SDNode<"X86ISD::SBB" ,     SDTIntBinOp>;
64
65 def X86shld    : SDNode<"X86ISD::SHLD",     SDTIntShiftDOp>;
66 def X86shrd    : SDNode<"X86ISD::SHRD",     SDTIntShiftDOp>;
67
68 def X86cmp     : SDNode<"X86ISD::CMP" ,     SDTX86CmpTest,  []>;
69 def X86test    : SDNode<"X86ISD::TEST",     SDTX86CmpTest,  []>;
70
71 def X86cmov    : SDNode<"X86ISD::CMOV",     SDTX86Cmov,    
72                         [SDNPOutFlag]>;
73 def X86brcond  : SDNode<"X86ISD::BRCOND",   SDTX86BrCond,
74                         [SDNPHasChain]>;
75 def X86setcc   : SDNode<"X86ISD::SETCC",    SDTX86SetCC,    []>;
76
77 def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
78                         [SDNPHasChain, SDNPOptInFlag]>;
79
80 def X86callseq_start :
81                  SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
82                         [SDNPHasChain]>;
83 def X86callseq_end :
84                  SDNode<"ISD::CALLSEQ_END",   SDT_X86CallSeqEnd,
85                         [SDNPHasChain]>;
86
87 def X86call    : SDNode<"X86ISD::CALL",     SDT_X86Call,
88                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
89
90 def X86fpget   : SDNode<"X86ISD::FP_GET_RESULT", SDTX86FpGet,
91                         [SDNPHasChain, SDNPInFlag]>;
92 def X86fpset   : SDNode<"X86ISD::FP_SET_RESULT", SDTX86FpSet,
93                         [SDNPHasChain, SDNPOutFlag]>;
94
95 def X86fld     : SDNode<"X86ISD::FLD",      SDTX86Fld,
96                         [SDNPHasChain]>;
97 def X86fst     : SDNode<"X86ISD::FST",      SDTX86Fst,
98                         [SDNPHasChain]>;
99 def X86fild64m : SDNode<"X86ISD::FILD64m",  SDTX86Fild64m,
100                         [SDNPHasChain]>;
101
102 def X86rdtsc   : SDNode<"X86ISD::RDTSC_DAG",SDTX86RdTsc,
103                         [SDNPHasChain, SDNPOutFlag]>;
104
105 //===----------------------------------------------------------------------===//
106 // X86 Operand Definitions.
107 //
108
109 // *mem - Operand definitions for the funky X86 addressing mode operands.
110 //
111 class X86MemOperand<string printMethod> : Operand<i32> {
112   let PrintMethod = printMethod;
113   let NumMIOperands = 4;
114   let MIOperandInfo = (ops R32, i8imm, R32, i32imm);
115 }
116
117 def i8mem   : X86MemOperand<"printi8mem">;
118 def i16mem  : X86MemOperand<"printi16mem">;
119 def i32mem  : X86MemOperand<"printi32mem">;
120 def i64mem  : X86MemOperand<"printi64mem">;
121 def f32mem  : X86MemOperand<"printf32mem">;
122 def f64mem  : X86MemOperand<"printf64mem">;
123 def f80mem  : X86MemOperand<"printf80mem">;
124
125 def SSECC : Operand<i8> {
126   let PrintMethod = "printSSECC";
127 }
128
129 // A couple of more descriptive operand definitions.
130 // 16-bits but only 8 bits are significant.
131 def i16i8imm  : Operand<i16>;
132 // 32-bits but only 8 bits are significant.
133 def i32i8imm  : Operand<i32>;
134
135 // PCRelative calls need special operand formatting.
136 let PrintMethod = "printCallOperand" in
137   def calltarget : Operand<i32>;
138
139 // Branch targets have OtherVT type.
140 def brtarget : Operand<OtherVT>;
141
142 //===----------------------------------------------------------------------===//
143 // X86 Complex Pattern Definitions.
144 //
145
146 // Define X86 specific addressing mode.
147 def addr    : ComplexPattern<i32, 4, "SelectAddr", []>;
148 def leaaddr : ComplexPattern<i32, 4, "SelectLEAAddr",
149                              [add, frameindex, constpool,
150                               globaladdr, tglobaladdr, externalsym]>;
151
152 //===----------------------------------------------------------------------===//
153 // X86 Instruction Format Definitions.
154 //
155
156 // Format specifies the encoding used by the instruction.  This is part of the
157 // ad-hoc solution used to emit machine instruction encodings by our machine
158 // code emitter.
159 class Format<bits<5> val> {
160   bits<5> Value = val;
161 }
162
163 def Pseudo     : Format<0>; def RawFrm     : Format<1>;
164 def AddRegFrm  : Format<2>; def MRMDestReg : Format<3>;
165 def MRMDestMem : Format<4>; def MRMSrcReg  : Format<5>;
166 def MRMSrcMem  : Format<6>;
167 def MRM0r  : Format<16>; def MRM1r  : Format<17>; def MRM2r  : Format<18>;
168 def MRM3r  : Format<19>; def MRM4r  : Format<20>; def MRM5r  : Format<21>;
169 def MRM6r  : Format<22>; def MRM7r  : Format<23>;
170 def MRM0m  : Format<24>; def MRM1m  : Format<25>; def MRM2m  : Format<26>;
171 def MRM3m  : Format<27>; def MRM4m  : Format<28>; def MRM5m  : Format<29>;
172 def MRM6m  : Format<30>; def MRM7m  : Format<31>;
173
174 //===----------------------------------------------------------------------===//
175 // X86 Instruction Predicate Definitions.
176 def HasSSE1 : Predicate<"X86Vector >= SSE">;
177 def HasSSE2 : Predicate<"X86Vector >= SSE2">;
178 def HasSSE3 : Predicate<"X86Vector >= SSE3">;
179 def FPStack : Predicate<"X86Vector < SSE2">;
180
181 //===----------------------------------------------------------------------===//
182 // X86 specific pattern fragments.
183 //
184
185 // ImmType - This specifies the immediate type used by an instruction. This is
186 // part of the ad-hoc solution used to emit machine instruction encodings by our
187 // machine code emitter.
188 class ImmType<bits<2> val> {
189   bits<2> Value = val;
190 }
191 def NoImm  : ImmType<0>;
192 def Imm8   : ImmType<1>;
193 def Imm16  : ImmType<2>;
194 def Imm32  : ImmType<3>;
195
196 // FPFormat - This specifies what form this FP instruction has.  This is used by
197 // the Floating-Point stackifier pass.
198 class FPFormat<bits<3> val> {
199   bits<3> Value = val;
200 }
201 def NotFP      : FPFormat<0>;
202 def ZeroArgFP  : FPFormat<1>;
203 def OneArgFP   : FPFormat<2>;
204 def OneArgFPRW : FPFormat<3>;
205 def TwoArgFP   : FPFormat<4>;
206 def CompareFP  : FPFormat<5>;
207 def CondMovFP  : FPFormat<6>;
208 def SpecialFP  : FPFormat<7>;
209
210
211 class X86Inst<bits<8> opcod, Format f, ImmType i, dag ops, string AsmStr>
212   : Instruction {
213   let Namespace = "X86";
214
215   bits<8> Opcode = opcod;
216   Format Form = f;
217   bits<5> FormBits = Form.Value;
218   ImmType ImmT = i;
219   bits<2> ImmTypeBits = ImmT.Value;
220
221   dag OperandList = ops;
222   string AsmString = AsmStr;
223
224   //
225   // Attributes specific to X86 instructions...
226   //
227   bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix?
228
229   bits<4> Prefix = 0;       // Which prefix byte does this inst have?
230   FPFormat FPForm;          // What flavor of FP instruction is this?
231   bits<3> FPFormBits = 0;
232 }
233
234 class Imp<list<Register> uses, list<Register> defs> {
235   list<Register> Uses = uses;
236   list<Register> Defs = defs;
237 }
238
239
240 // Prefix byte classes which are used to indicate to the ad-hoc machine code
241 // emitter that various prefix bytes are required.
242 class OpSize { bit hasOpSizePrefix = 1; }
243 class TB     { bits<4> Prefix = 1; }
244 class REP    { bits<4> Prefix = 2; }
245 class D8     { bits<4> Prefix = 3; }
246 class D9     { bits<4> Prefix = 4; }
247 class DA     { bits<4> Prefix = 5; }
248 class DB     { bits<4> Prefix = 6; }
249 class DC     { bits<4> Prefix = 7; }
250 class DD     { bits<4> Prefix = 8; }
251 class DE     { bits<4> Prefix = 9; }
252 class DF     { bits<4> Prefix = 10; }
253 class XD     { bits<4> Prefix = 11; }
254 class XS     { bits<4> Prefix = 12; }
255
256
257 //===----------------------------------------------------------------------===//
258 // Pattern fragments...
259 //
260
261 // X86 specific condition code. These correspond to CondCode in
262 // X86ISelLowering.h. They must be kept in synch.
263 def X86_COND_A   : PatLeaf<(i8 0)>;
264 def X86_COND_AE  : PatLeaf<(i8 1)>;
265 def X86_COND_B   : PatLeaf<(i8 2)>;
266 def X86_COND_BE  : PatLeaf<(i8 3)>;
267 def X86_COND_E   : PatLeaf<(i8 4)>;
268 def X86_COND_G   : PatLeaf<(i8 5)>;
269 def X86_COND_GE  : PatLeaf<(i8 6)>;
270 def X86_COND_L   : PatLeaf<(i8 7)>;
271 def X86_COND_LE  : PatLeaf<(i8 8)>;
272 def X86_COND_NE  : PatLeaf<(i8 9)>;
273 def X86_COND_NO  : PatLeaf<(i8 10)>;
274 def X86_COND_NP  : PatLeaf<(i8 11)>;
275 def X86_COND_NS  : PatLeaf<(i8 12)>;
276 def X86_COND_O   : PatLeaf<(i8 13)>;
277 def X86_COND_P   : PatLeaf<(i8 14)>;
278 def X86_COND_S   : PatLeaf<(i8 15)>;
279
280 def i16immSExt8  : PatLeaf<(i16 imm), [{
281   // i16immSExt8 predicate - True if the 16-bit immediate fits in a 8-bit
282   // sign extended field.
283   return (int)N->getValue() == (signed char)N->getValue();
284 }]>;
285
286 def i32immSExt8  : PatLeaf<(i32 imm), [{
287   // i32immSExt8 predicate - True if the 32-bit immediate fits in a 8-bit
288   // sign extended field.
289   return (int)N->getValue() == (signed char)N->getValue();
290 }]>;
291
292 def i16immZExt8  : PatLeaf<(i16 imm), [{
293   // i16immZExt8 predicate - True if the 16-bit immediate fits in a 8-bit zero
294   // extended field.
295   return (unsigned)N->getValue() == (unsigned char)N->getValue();
296 }]>;
297
298 def fp32imm0 : PatLeaf<(f32 fpimm), [{
299   return N->isExactlyValue(+0.0);
300 }]>;
301
302 def fp64imm0 : PatLeaf<(f64 fpimm), [{
303   return N->isExactlyValue(+0.0);
304 }]>;
305
306 def fp64immneg0 : PatLeaf<(f64 fpimm), [{
307   return N->isExactlyValue(-0.0);
308 }]>;
309
310 def fp64imm1 : PatLeaf<(f64 fpimm), [{
311   return N->isExactlyValue(+1.0);
312 }]>;
313
314 def fp64immneg1 : PatLeaf<(f64 fpimm), [{
315   return N->isExactlyValue(-1.0);
316 }]>;
317
318 // Helper fragments for loads.
319 def loadi8  : PatFrag<(ops node:$ptr), (i8  (load node:$ptr))>;
320 def loadi16 : PatFrag<(ops node:$ptr), (i16 (load node:$ptr))>;
321 def loadi32 : PatFrag<(ops node:$ptr), (i32 (load node:$ptr))>;
322 def loadf32 : PatFrag<(ops node:$ptr), (f32 (load node:$ptr))>;
323 def loadf64 : PatFrag<(ops node:$ptr), (f64 (load node:$ptr))>;
324
325 def sextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (sextload node:$ptr, i1))>;
326 def sextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (sextload node:$ptr, i1))>;
327 def sextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextload node:$ptr, i8))>;
328 def sextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextload node:$ptr, i8))>;
329 def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextload node:$ptr, i16))>;
330
331 def zextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextload node:$ptr, i1))>;
332 def zextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextload node:$ptr, i1))>;
333 def zextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextload node:$ptr, i8))>;
334 def zextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextload node:$ptr, i8))>;
335 def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextload node:$ptr, i16))>;
336
337 def extloadi8i1    : PatFrag<(ops node:$ptr), (i8  (extload node:$ptr, i1))>;
338 def extloadf64f32  : PatFrag<(ops node:$ptr), (f64 (extload node:$ptr, f32))>;
339
340 //===----------------------------------------------------------------------===//
341 // Instruction templates...
342
343 class I<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
344   : X86Inst<o, f, NoImm, ops, asm> {
345   let Pattern = pattern;
346 }
347 class Ii8 <bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
348   : X86Inst<o, f, Imm8 , ops, asm> {
349   let Pattern = pattern;
350 }
351 class Ii16<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
352   : X86Inst<o, f, Imm16, ops, asm> {
353   let Pattern = pattern;
354 }
355 class Ii32<bits<8> o, Format f, dag ops, string asm, list<dag> pattern>
356   : X86Inst<o, f, Imm32, ops, asm> {
357   let Pattern = pattern;
358 }
359
360 //===----------------------------------------------------------------------===//
361 // Instruction list...
362 //
363
364 // Pseudo-instructions:
365 def PHI : I<0, Pseudo, (ops variable_ops), "PHINODE", []>;        // PHI node.
366
367 def ADJCALLSTACKDOWN : I<0, Pseudo, (ops i32imm:$amt), "#ADJCALLSTACKDOWN",
368                          [(X86callseq_start imm:$amt)]>;
369 def ADJCALLSTACKUP   : I<0, Pseudo, (ops i32imm:$amt1, i32imm:$amt2),
370                          "#ADJCALLSTACKUP",
371                          [(X86callseq_end imm:$amt1, imm:$amt2)]>;
372 def IMPLICIT_USE     : I<0, Pseudo, (ops variable_ops), "#IMPLICIT_USE", []>;
373 def IMPLICIT_DEF     : I<0, Pseudo, (ops variable_ops), "#IMPLICIT_DEF", []>;
374 def IMPLICIT_DEF_R8  : I<0, Pseudo, (ops R8:$dst),
375                          "#IMPLICIT_DEF $dst",
376                          [(set R8:$dst, (undef))]>;
377 def IMPLICIT_DEF_R16  : I<0, Pseudo, (ops R16:$dst),
378                          "#IMPLICIT_DEF $dst",
379                          [(set R16:$dst, (undef))]>;
380 def IMPLICIT_DEF_R32  : I<0, Pseudo, (ops R32:$dst),
381                          "#IMPLICIT_DEF $dst",
382                          [(set R32:$dst, (undef))]>;
383 def IMPLICIT_DEF_FR32 : I<0, Pseudo, (ops FR32:$dst),
384                          "#IMPLICIT_DEF $dst",
385                          [(set FR32:$dst, (undef))]>, Requires<[HasSSE2]>;
386 def IMPLICIT_DEF_FR64 : I<0, Pseudo, (ops FR64:$dst),
387                          "#IMPLICIT_DEF $dst",
388                          [(set FR64:$dst, (undef))]>, Requires<[HasSSE2]>;
389
390
391 // CMOV* - Used to implement the SSE SELECT DAG operation.  Expanded by the
392 // scheduler into a branch sequence.
393 let usesCustomDAGSchedInserter = 1 in {  // Expanded by the scheduler.
394   def CMOV_FR32 : I<0, Pseudo,
395                     (ops FR32:$dst, FR32:$t, FR32:$f, i8imm:$cond),
396                     "#CMOV PSEUDO!",
397                     [(set FR32:$dst, (X86cmov FR32:$t, FR32:$f, imm:$cond,
398                                       STATUS))]>;
399   def CMOV_FR64 : I<0, Pseudo,
400                     (ops FR64:$dst, FR64:$t, FR64:$f, i8imm:$cond),
401                     "#CMOV PSEUDO!",
402                     [(set FR64:$dst, (X86cmov FR64:$t, FR64:$f, imm:$cond,
403                                       STATUS))]>;
404 }
405
406 let isTerminator = 1 in
407   let Defs = [FP0, FP1, FP2, FP3, FP4, FP5, FP6] in
408     def FP_REG_KILL  : I<0, Pseudo, (ops), "#FP_REG_KILL", []>;
409
410
411 // Nop
412 def NOOP : I<0x90, RawFrm, (ops), "nop", []>;
413
414 //===----------------------------------------------------------------------===//
415 //  Control Flow Instructions...
416 //
417
418 // Return instructions.
419 let isTerminator = 1, isReturn = 1, isBarrier = 1,
420     hasCtrlDep = 1, noResults = 1 in {
421   def RET    : I<0xC3, RawFrm, (ops), "ret", [(X86retflag 0)]>;
422   def RETI   : Ii16<0xC2, RawFrm, (ops i16imm:$amt), "ret $amt",
423                     [(X86retflag imm:$amt)]>;
424 }
425
426 // All branches are RawFrm, Void, Branch, and Terminators
427 let isBranch = 1, isTerminator = 1, noResults = 1 in
428   class IBr<bits<8> opcode, dag ops, string asm, list<dag> pattern> :
429         I<opcode, RawFrm, ops, asm, pattern>;
430
431 // Conditional branches
432 let isBarrier = 1 in
433   def JMP : IBr<0xE9, (ops brtarget:$dst), "jmp $dst", [(br bb:$dst)]>;
434
435 def JE  : IBr<0x84, (ops brtarget:$dst), "je $dst",
436               [(X86brcond bb:$dst, X86_COND_E, STATUS)]>, Imp<[STATUS],[]>, TB;
437 def JNE : IBr<0x85, (ops brtarget:$dst), "jne $dst",
438               [(X86brcond bb:$dst, X86_COND_NE, STATUS)]>, Imp<[STATUS],[]>, TB;
439 def JL  : IBr<0x8C, (ops brtarget:$dst), "jl $dst",
440               [(X86brcond bb:$dst, X86_COND_L, STATUS)]>, Imp<[STATUS],[]>, TB;
441 def JLE : IBr<0x8E, (ops brtarget:$dst), "jle $dst",
442               [(X86brcond bb:$dst, X86_COND_LE, STATUS)]>, Imp<[STATUS],[]>, TB;
443 def JG  : IBr<0x8F, (ops brtarget:$dst), "jg $dst",
444               [(X86brcond bb:$dst, X86_COND_G, STATUS)]>, Imp<[STATUS],[]>, TB;
445 def JGE : IBr<0x8D, (ops brtarget:$dst), "jge $dst",
446               [(X86brcond bb:$dst, X86_COND_GE, STATUS)]>, Imp<[STATUS],[]>, TB;
447
448 def JB  : IBr<0x82, (ops brtarget:$dst), "jb $dst",
449               [(X86brcond bb:$dst, X86_COND_B, STATUS)]>, Imp<[STATUS],[]>, TB;
450 def JBE : IBr<0x86, (ops brtarget:$dst), "jbe $dst",
451               [(X86brcond bb:$dst, X86_COND_BE, STATUS)]>, Imp<[STATUS],[]>, TB;
452 def JA  : IBr<0x87, (ops brtarget:$dst), "ja $dst",
453               [(X86brcond bb:$dst, X86_COND_A, STATUS)]>, Imp<[STATUS],[]>, TB;
454 def JAE : IBr<0x83, (ops brtarget:$dst), "jae $dst",
455               [(X86brcond bb:$dst, X86_COND_AE, STATUS)]>, Imp<[STATUS],[]>, TB;
456
457 def JS  : IBr<0x88, (ops brtarget:$dst), "js $dst",
458               [(X86brcond bb:$dst, X86_COND_S, STATUS)]>, Imp<[STATUS],[]>, TB;
459 def JNS : IBr<0x89, (ops brtarget:$dst), "jns $dst",
460               [(X86brcond bb:$dst, X86_COND_NS, STATUS)]>, Imp<[STATUS],[]>, TB;
461 def JP  : IBr<0x8A, (ops brtarget:$dst), "jp $dst",
462               [(X86brcond bb:$dst, X86_COND_P, STATUS)]>, Imp<[STATUS],[]>, TB;
463 def JNP : IBr<0x8B, (ops brtarget:$dst), "jnp $dst",
464               [(X86brcond bb:$dst, X86_COND_NP, STATUS)]>, Imp<[STATUS],[]>, TB;
465 def JO  : IBr<0x80, (ops brtarget:$dst), "jo $dst",
466               [(X86brcond bb:$dst, X86_COND_O, STATUS)]>, Imp<[STATUS],[]>, TB;
467 def JNO : IBr<0x81, (ops brtarget:$dst), "jno $dst",
468               [(X86brcond bb:$dst, X86_COND_NO, STATUS)]>, Imp<[STATUS],[]>, TB;
469
470 //===----------------------------------------------------------------------===//
471 //  Call Instructions...
472 //
473 let isCall = 1, noResults = 1 in
474   // All calls clobber the non-callee saved registers...
475   let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
476               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7] in {
477     def CALLpcrel32 : I<0xE8, RawFrm, (ops calltarget:$dst), "call $dst",
478                       []>;
479     def CALL32r     : I<0xFF, MRM2r, (ops R32:$dst), "call {*}$dst",
480                       [(X86call R32:$dst)]>;
481     def CALL32m     : I<0xFF, MRM2m, (ops i32mem:$dst), "call {*}$dst",
482                       [(X86call (loadi32 addr:$dst))]>;
483   }
484
485 // Tail call stuff.
486 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, noResults = 1 in
487   def TAILJMPd : IBr<0xE9, (ops calltarget:$dst), "jmp $dst  # TAIL CALL", []>;
488 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, noResults = 1 in
489   def TAILJMPr : I<0xFF, MRM4r, (ops R32:$dst), "jmp {*}$dst  # TAIL CALL", []>;
490 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, noResults = 1 in
491   def TAILJMPm : I<0xFF, MRM4m, (ops i32mem:$dst),
492                    "jmp {*}$dst  # TAIL CALL", []>;
493
494 // ADJSTACKPTRri - This is a standard ADD32ri instruction, identical in every
495 // way, except that it is marked as being a terminator.  This causes the epilog
496 // inserter to insert reloads of callee saved registers BEFORE this.  We need
497 // this until we have a more accurate way of tracking where the stack pointer is
498 // within a function.
499 let isTerminator = 1, isTwoAddress = 1 in
500   def ADJSTACKPTRri : Ii32<0x81, MRM0r, (ops R32:$dst, R32:$src1, i32imm:$src2),
501                            "add{l} {$src2, $dst|$dst, $src2}", []>;
502
503 //===----------------------------------------------------------------------===//
504 //  Miscellaneous Instructions...
505 //
506 def LEAVE    : I<0xC9, RawFrm,
507                  (ops), "leave", []>, Imp<[EBP,ESP],[EBP,ESP]>;
508 def POP32r   : I<0x58, AddRegFrm,
509                  (ops R32:$reg), "pop{l} $reg", []>, Imp<[ESP],[ESP]>;
510
511 let isTwoAddress = 1 in                               // R32 = bswap R32
512   def BSWAP32r : I<0xC8, AddRegFrm,
513                    (ops R32:$dst, R32:$src), "bswap{l} $dst", []>, TB;
514
515 def XCHG8rr  : I<0x86, MRMDestReg,                    // xchg R8, R8
516                  (ops R8:$src1, R8:$src2),
517                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
518 def XCHG16rr : I<0x87, MRMDestReg,                    // xchg R16, R16
519                  (ops R16:$src1, R16:$src2),
520                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
521 def XCHG32rr : I<0x87, MRMDestReg,                    // xchg R32, R32
522                  (ops R32:$src1, R32:$src2),
523                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
524
525 def XCHG8mr  : I<0x86, MRMDestMem,
526                  (ops i8mem:$src1, R8:$src2),
527                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
528 def XCHG16mr : I<0x87, MRMDestMem,
529                  (ops i16mem:$src1, R16:$src2),
530                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
531 def XCHG32mr : I<0x87, MRMDestMem,
532                  (ops i32mem:$src1, R32:$src2),
533                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
534 def XCHG8rm  : I<0x86, MRMSrcMem,
535                  (ops R8:$src1, i8mem:$src2),
536                  "xchg{b} {$src2|$src1}, {$src1|$src2}", []>;
537 def XCHG16rm : I<0x87, MRMSrcMem,
538                  (ops R16:$src1, i16mem:$src2),
539                  "xchg{w} {$src2|$src1}, {$src1|$src2}", []>, OpSize;
540 def XCHG32rm : I<0x87, MRMSrcMem,
541                  (ops R32:$src1, i32mem:$src2),
542                  "xchg{l} {$src2|$src1}, {$src1|$src2}", []>;
543
544 def LEA16r   : I<0x8D, MRMSrcMem,
545                  (ops R16:$dst, i32mem:$src),
546                  "lea{w} {$src|$dst}, {$dst|$src}", []>, OpSize;
547 def LEA32r   : I<0x8D, MRMSrcMem,
548                  (ops R32:$dst, i32mem:$src),
549                  "lea{l} {$src|$dst}, {$dst|$src}",
550                  [(set R32:$dst, leaaddr:$src)]>;
551
552 def REP_MOVSB : I<0xA4, RawFrm, (ops), "{rep;movsb|rep movsb}", []>,
553                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP;
554 def REP_MOVSW : I<0xA5, RawFrm, (ops), "{rep;movsw|rep movsw}", []>,
555                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP, OpSize;
556 def REP_MOVSD : I<0xA5, RawFrm, (ops), "{rep;movsd|rep movsd}", []>,
557                 Imp<[ECX,EDI,ESI], [ECX,EDI,ESI]>, REP;
558
559 def REP_STOSB : I<0xAA, RawFrm, (ops), "{rep;stosb|rep stosb}", []>,
560                 Imp<[AL,ECX,EDI], [ECX,EDI]>, REP;
561 def REP_STOSW : I<0xAB, RawFrm, (ops), "{rep;stosw|rep stosw}", []>,
562                 Imp<[AX,ECX,EDI], [ECX,EDI]>, REP, OpSize;
563 def REP_STOSD : I<0xAB, RawFrm, (ops), "{rep;stosl|rep stosd}", []>,
564                 Imp<[EAX,ECX,EDI], [ECX,EDI]>, REP;
565
566
567 //===----------------------------------------------------------------------===//
568 //  Input/Output Instructions...
569 //
570 def IN8rr  : I<0xEC, RawFrm, (ops),
571                "in{b} {%dx, %al|%AL, %DX}",
572                [(set AL, (readport DX))]>,  Imp<[DX], [AL]>;
573 def IN16rr : I<0xED, RawFrm, (ops),
574                "in{w} {%dx, %ax|%AX, %DX}",
575                [(set AX, (readport DX))]>,  Imp<[DX], [AX]>, OpSize;
576 def IN32rr : I<0xED, RawFrm, (ops),
577                "in{l} {%dx, %eax|%EAX, %DX}",
578                [(set EAX, (readport DX))]>, Imp<[DX],[EAX]>;
579
580 def IN8ri  : Ii8<0xE4, RawFrm, (ops i16i8imm:$port),
581                   "in{b} {$port, %al|%AL, $port}",
582                  [(set AL, (readport i16immZExt8:$port))]>,
583              Imp<[], [AL]>;
584 def IN16ri : Ii8<0xE5, RawFrm, (ops i16i8imm:$port),
585                   "in{w} {$port, %ax|%AX, $port}",
586                  [(set AX, (readport i16immZExt8:$port))]>,
587              Imp<[], [AX]>, OpSize;
588 def IN32ri : Ii8<0xE5, RawFrm, (ops i16i8imm:$port),
589                   "in{l} {$port, %eax|%EAX, $port}",
590                  [(set EAX, (readport i16immZExt8:$port))]>,
591              Imp<[],[EAX]>;
592
593 def OUT8rr  : I<0xEE, RawFrm, (ops),
594                 "out{b} {%al, %dx|%DX, %AL}",
595                 [(writeport AL, DX)]>,  Imp<[DX,  AL], []>;
596 def OUT16rr : I<0xEF, RawFrm, (ops),
597                 "out{w} {%ax, %dx|%DX, %AX}",
598                 [(writeport AX, DX)]>,  Imp<[DX,  AX], []>, OpSize;
599 def OUT32rr : I<0xEF, RawFrm, (ops),
600                 "out{l} {%eax, %dx|%DX, %EAX}",
601                 [(writeport EAX, DX)]>, Imp<[DX, EAX], []>;
602
603 def OUT8ir  : Ii8<0xE6, RawFrm, (ops i16i8imm:$port),
604                    "out{b} {%al, $port|$port, %AL}",
605                    [(writeport AL, i16immZExt8:$port)]>,
606               Imp<[AL], []>;
607 def OUT16ir : Ii8<0xE7, RawFrm, (ops i16i8imm:$port),
608                    "out{w} {%ax, $port|$port, %AX}",
609                    [(writeport AX, i16immZExt8:$port)]>,
610               Imp<[AX], []>, OpSize;
611 def OUT32ir : Ii8<0xE7, RawFrm, (ops i16i8imm:$port),
612                    "out{l} {%eax, $port|$port, %EAX}",
613                    [(writeport EAX, i16immZExt8:$port)]>,
614               Imp<[EAX], []>;
615
616 //===----------------------------------------------------------------------===//
617 //  Move Instructions...
618 //
619 def MOV8rr  : I<0x88, MRMDestReg, (ops R8 :$dst, R8 :$src),
620                 "mov{b} {$src, $dst|$dst, $src}", []>;
621 def MOV16rr : I<0x89, MRMDestReg, (ops R16:$dst, R16:$src),
622                 "mov{w} {$src, $dst|$dst, $src}", []>, OpSize;
623 def MOV32rr : I<0x89, MRMDestReg, (ops R32:$dst, R32:$src),
624                 "mov{l} {$src, $dst|$dst, $src}", []>;
625 def MOV8ri  : Ii8 <0xB0, AddRegFrm, (ops R8 :$dst, i8imm :$src),
626                    "mov{b} {$src, $dst|$dst, $src}",
627                    [(set R8:$dst, imm:$src)]>;
628 def MOV16ri : Ii16<0xB8, AddRegFrm, (ops R16:$dst, i16imm:$src),
629                    "mov{w} {$src, $dst|$dst, $src}",
630                    [(set R16:$dst, imm:$src)]>, OpSize;
631 def MOV32ri : Ii32<0xB8, AddRegFrm, (ops R32:$dst, i32imm:$src),
632                    "mov{l} {$src, $dst|$dst, $src}",
633                    [(set R32:$dst, imm:$src)]>;
634 def MOV8mi  : Ii8 <0xC6, MRM0m, (ops i8mem :$dst, i8imm :$src),
635                    "mov{b} {$src, $dst|$dst, $src}",
636                    [(store (i8 imm:$src), addr:$dst)]>;
637 def MOV16mi : Ii16<0xC7, MRM0m, (ops i16mem:$dst, i16imm:$src),
638                    "mov{w} {$src, $dst|$dst, $src}",
639                    [(store (i16 imm:$src), addr:$dst)]>, OpSize;
640 def MOV32mi : Ii32<0xC7, MRM0m, (ops i32mem:$dst, i32imm:$src),
641                    "mov{l} {$src, $dst|$dst, $src}",
642                    [(store (i32 imm:$src), addr:$dst)]>;
643
644 def MOV8rm  : I<0x8A, MRMSrcMem, (ops R8 :$dst, i8mem :$src),
645                 "mov{b} {$src, $dst|$dst, $src}",
646                 [(set R8:$dst, (load addr:$src))]>;
647 def MOV16rm : I<0x8B, MRMSrcMem, (ops R16:$dst, i16mem:$src),
648                 "mov{w} {$src, $dst|$dst, $src}",
649                 [(set R16:$dst, (load addr:$src))]>, OpSize;
650 def MOV32rm : I<0x8B, MRMSrcMem, (ops R32:$dst, i32mem:$src),
651                 "mov{l} {$src, $dst|$dst, $src}",
652                 [(set R32:$dst, (load addr:$src))]>;
653
654 def MOV8mr  : I<0x88, MRMDestMem, (ops i8mem :$dst, R8 :$src),
655                 "mov{b} {$src, $dst|$dst, $src}",
656                 [(store R8:$src, addr:$dst)]>;
657 def MOV16mr : I<0x89, MRMDestMem, (ops i16mem:$dst, R16:$src),
658                 "mov{w} {$src, $dst|$dst, $src}",
659                 [(store R16:$src, addr:$dst)]>, OpSize;
660 def MOV32mr : I<0x89, MRMDestMem, (ops i32mem:$dst, R32:$src),
661                 "mov{l} {$src, $dst|$dst, $src}",
662                 [(store R32:$src, addr:$dst)]>;
663                 
664 //===----------------------------------------------------------------------===//
665 //  Fixed-Register Multiplication and Division Instructions...
666 //
667
668 // Extra precision multiplication
669 def MUL8r  : I<0xF6, MRM4r, (ops R8:$src), "mul{b} $src", []>,
670              Imp<[AL],[AX]>;               // AL,AH = AL*R8
671 def MUL16r : I<0xF7, MRM4r, (ops R16:$src), "mul{w} $src", []>,
672              Imp<[AX],[AX,DX]>, OpSize;    // AX,DX = AX*R16
673 def MUL32r : I<0xF7, MRM4r, (ops R32:$src), "mul{l} $src", []>,
674              Imp<[EAX],[EAX,EDX]>;         // EAX,EDX = EAX*R32
675 def MUL8m  : I<0xF6, MRM4m, (ops i8mem :$src),
676                "mul{b} $src", []>, Imp<[AL],[AX]>;          // AL,AH = AL*[mem8]
677 def MUL16m : I<0xF7, MRM4m, (ops i16mem:$src),
678                "mul{w} $src", []>, Imp<[AX],[AX,DX]>,
679                OpSize; // AX,DX = AX*[mem16]
680 def MUL32m : I<0xF7, MRM4m, (ops i32mem:$src),
681                "mul{l} $src", []>, Imp<[EAX],[EAX,EDX]>;// EAX,EDX = EAX*[mem32]
682
683 def IMUL8r  : I<0xF6, MRM5r, (ops R8:$src), "imul{b} $src", []>,
684               Imp<[AL],[AX]>;               // AL,AH = AL*R8
685 def IMUL16r : I<0xF7, MRM5r, (ops R16:$src), "imul{w} $src", []>,
686               Imp<[AX],[AX,DX]>, OpSize;    // AX,DX = AX*R16
687 def IMUL32r : I<0xF7, MRM5r, (ops R32:$src), "imul{l} $src", []>,
688               Imp<[EAX],[EAX,EDX]>;         // EAX,EDX = EAX*R32
689 def IMUL8m  : I<0xF6, MRM5m, (ops i8mem :$src),
690                 "imul{b} $src", []>, Imp<[AL],[AX]>;        // AL,AH = AL*[mem8]
691 def IMUL16m : I<0xF7, MRM5m, (ops i16mem:$src),
692                 "imul{w} $src", []>, Imp<[AX],[AX,DX]>,
693                 OpSize; // AX,DX = AX*[mem16]
694 def IMUL32m : I<0xF7, MRM5m, (ops i32mem:$src),
695                 "imul{l} $src", []>,
696                 Imp<[EAX],[EAX,EDX]>;  // EAX,EDX = EAX*[mem32]
697
698 // unsigned division/remainder
699 def DIV8r  : I<0xF6, MRM6r, (ops R8:$src),          // AX/r8 = AL,AH
700                "div{b} $src", []>, Imp<[AX],[AX]>;
701 def DIV16r : I<0xF7, MRM6r, (ops R16:$src),         // DX:AX/r16 = AX,DX
702                "div{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
703 def DIV32r : I<0xF7, MRM6r, (ops R32:$src),         // EDX:EAX/r32 = EAX,EDX
704                "div{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
705 def DIV8m  : I<0xF6, MRM6m, (ops i8mem:$src),       // AX/[mem8] = AL,AH
706                "div{b} $src", []>, Imp<[AX],[AX]>;
707 def DIV16m : I<0xF7, MRM6m, (ops i16mem:$src),      // DX:AX/[mem16] = AX,DX
708                "div{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
709 def DIV32m : I<0xF7, MRM6m, (ops i32mem:$src),      // EDX:EAX/[mem32] = EAX,EDX
710                "div{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
711
712 // Signed division/remainder.
713 def IDIV8r : I<0xF6, MRM7r, (ops R8:$src),          // AX/r8 = AL,AH
714                "idiv{b} $src", []>, Imp<[AX],[AX]>;
715 def IDIV16r: I<0xF7, MRM7r, (ops R16:$src),         // DX:AX/r16 = AX,DX
716                "idiv{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
717 def IDIV32r: I<0xF7, MRM7r, (ops R32:$src),         // EDX:EAX/r32 = EAX,EDX
718                "idiv{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
719 def IDIV8m : I<0xF6, MRM7m, (ops i8mem:$src),      // AX/[mem8] = AL,AH
720                "idiv{b} $src", []>, Imp<[AX],[AX]>;
721 def IDIV16m: I<0xF7, MRM7m, (ops i16mem:$src),     // DX:AX/[mem16] = AX,DX
722                "idiv{w} $src", []>, Imp<[AX,DX],[AX,DX]>, OpSize;
723 def IDIV32m: I<0xF7, MRM7m, (ops i32mem:$src),     // EDX:EAX/[mem32] = EAX,EDX
724                "idiv{l} $src", []>, Imp<[EAX,EDX],[EAX,EDX]>;
725
726 // Sign-extenders for division.
727 def CBW : I<0x98, RawFrm, (ops),
728             "{cbtw|cbw}", []>, Imp<[AL],[AH]>;   // AX = signext(AL)
729 def CWD : I<0x99, RawFrm, (ops),
730             "{cwtd|cwd}", []>, Imp<[AX],[DX]>;   // DX:AX = signext(AX)
731 def CDQ : I<0x99, RawFrm, (ops),
732             "{cltd|cdq}", []>, Imp<[EAX],[EDX]>; // EDX:EAX = signext(EAX)
733           
734
735 //===----------------------------------------------------------------------===//
736 //  Two address Instructions...
737 //
738 let isTwoAddress = 1 in {
739
740 // Conditional moves
741 def CMOVB16rr : I<0x42, MRMSrcReg,       // if <u, R16 = R16
742                   (ops R16:$dst, R16:$src1, R16:$src2),
743                   "cmovb {$src2, $dst|$dst, $src2}",
744                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
745                                    X86_COND_B, STATUS))]>,
746                   Imp<[STATUS],[]>, TB, OpSize;
747 def CMOVB16rm : I<0x42, MRMSrcMem,       // if <u, R16 = [mem16]
748                   (ops R16:$dst, R16:$src1, i16mem:$src2),
749                   "cmovb {$src2, $dst|$dst, $src2}",
750                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
751                                    X86_COND_B, STATUS))]>,
752                   Imp<[STATUS],[]>, TB, OpSize;
753 def CMOVB32rr : I<0x42, MRMSrcReg,       // if <u, R32 = R32
754                   (ops R32:$dst, R32:$src1, R32:$src2),
755                   "cmovb {$src2, $dst|$dst, $src2}",
756                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
757                                    X86_COND_B, STATUS))]>,
758                   Imp<[STATUS],[]>,  TB;
759 def CMOVB32rm : I<0x42, MRMSrcMem,       // if <u, R32 = [mem32]
760                   (ops R32:$dst, R32:$src1, i32mem:$src2),
761                   "cmovb {$src2, $dst|$dst, $src2}",
762                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
763                                    X86_COND_B, STATUS))]>,
764                   Imp<[STATUS],[]>,  TB;
765
766 def CMOVAE16rr: I<0x43, MRMSrcReg,       // if >=u, R16 = R16
767                   (ops R16:$dst, R16:$src1, R16:$src2),
768                   "cmovae {$src2, $dst|$dst, $src2}",
769                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
770                                    X86_COND_AE, STATUS))]>,
771                   Imp<[STATUS],[]>,  TB, OpSize;
772 def CMOVAE16rm: I<0x43, MRMSrcMem,       // if >=u, R16 = [mem16]
773                   (ops R16:$dst, R16:$src1, i16mem:$src2),
774                   "cmovae {$src2, $dst|$dst, $src2}",
775                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
776                                    X86_COND_AE, STATUS))]>,
777                   Imp<[STATUS],[]>,  TB, OpSize;
778 def CMOVAE32rr: I<0x43, MRMSrcReg,       // if >=u, R32 = R32
779                   (ops R32:$dst, R32:$src1, R32:$src2),
780                   "cmovae {$src2, $dst|$dst, $src2}",
781                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
782                                    X86_COND_AE, STATUS))]>,
783                   Imp<[STATUS],[]>,  TB;
784 def CMOVAE32rm: I<0x43, MRMSrcMem,       // if >=u, R32 = [mem32]
785                   (ops R32:$dst, R32:$src1, i32mem:$src2),
786                   "cmovae {$src2, $dst|$dst, $src2}",
787                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
788                                    X86_COND_AE, STATUS))]>,
789                   Imp<[STATUS],[]>,  TB;
790
791 def CMOVE16rr : I<0x44, MRMSrcReg,       // if ==, R16 = R16
792                   (ops R16:$dst, R16:$src1, R16:$src2),
793                   "cmove {$src2, $dst|$dst, $src2}",
794                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
795                                    X86_COND_E, STATUS))]>,
796                   Imp<[STATUS],[]>,  TB, OpSize;
797 def CMOVE16rm : I<0x44, MRMSrcMem,       // if ==, R16 = [mem16]
798                   (ops R16:$dst, R16:$src1, i16mem:$src2),
799                   "cmove {$src2, $dst|$dst, $src2}",
800                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
801                                    X86_COND_E, STATUS))]>,
802                   Imp<[STATUS],[]>,  TB, OpSize;
803 def CMOVE32rr : I<0x44, MRMSrcReg,       // if ==, R32 = R32
804                   (ops R32:$dst, R32:$src1, R32:$src2),
805                   "cmove {$src2, $dst|$dst, $src2}",
806                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
807                                    X86_COND_E, STATUS))]>,
808                   Imp<[STATUS],[]>,  TB;
809 def CMOVE32rm : I<0x44, MRMSrcMem,       // if ==, R32 = [mem32]
810                   (ops R32:$dst, R32:$src1, i32mem:$src2),
811                   "cmove {$src2, $dst|$dst, $src2}",
812                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
813                                    X86_COND_E, STATUS))]>,
814                   Imp<[STATUS],[]>,  TB;
815
816 def CMOVNE16rr: I<0x45, MRMSrcReg,       // if !=, R16 = R16
817                   (ops R16:$dst, R16:$src1, R16:$src2),
818                   "cmovne {$src2, $dst|$dst, $src2}",
819                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
820                                    X86_COND_NE, STATUS))]>,
821                   Imp<[STATUS],[]>,  TB, OpSize;
822 def CMOVNE16rm: I<0x45, MRMSrcMem,       // if !=, R16 = [mem16]
823                   (ops R16:$dst, R16:$src1, i16mem:$src2),
824                   "cmovne {$src2, $dst|$dst, $src2}",
825                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
826                                    X86_COND_NE, STATUS))]>,
827                   Imp<[STATUS],[]>,  TB, OpSize;
828 def CMOVNE32rr: I<0x45, MRMSrcReg,       // if !=, R32 = R32
829                   (ops R32:$dst, R32:$src1, R32:$src2),
830                   "cmovne {$src2, $dst|$dst, $src2}",
831                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
832                                    X86_COND_NE, STATUS))]>,
833                   Imp<[STATUS],[]>,  TB;
834 def CMOVNE32rm: I<0x45, MRMSrcMem,       // if !=, R32 = [mem32]
835                   (ops R32:$dst, R32:$src1, i32mem:$src2),
836                   "cmovne {$src2, $dst|$dst, $src2}",
837                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
838                                    X86_COND_NE, STATUS))]>,
839                   Imp<[STATUS],[]>,  TB;
840
841 def CMOVBE16rr: I<0x46, MRMSrcReg,       // if <=u, R16 = R16
842                   (ops R16:$dst, R16:$src1, R16:$src2),
843                   "cmovbe {$src2, $dst|$dst, $src2}",
844                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
845                                    X86_COND_BE, STATUS))]>,
846                   Imp<[STATUS],[]>,  TB, OpSize;
847 def CMOVBE16rm: I<0x46, MRMSrcMem,       // if <=u, R16 = [mem16]
848                   (ops R16:$dst, R16:$src1, i16mem:$src2),
849                   "cmovbe {$src2, $dst|$dst, $src2}",
850                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
851                                    X86_COND_BE, STATUS))]>,
852                   Imp<[STATUS],[]>,  TB, OpSize;
853 def CMOVBE32rr: I<0x46, MRMSrcReg,       // if <=u, R32 = R32
854                   (ops R32:$dst, R32:$src1, R32:$src2),
855                   "cmovbe {$src2, $dst|$dst, $src2}",
856                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
857                                    X86_COND_BE, STATUS))]>,
858                   Imp<[STATUS],[]>,  TB;
859 def CMOVBE32rm: I<0x46, MRMSrcMem,       // if <=u, R32 = [mem32]
860                   (ops R32:$dst, R32:$src1, i32mem:$src2),
861                   "cmovbe {$src2, $dst|$dst, $src2}",
862                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
863                                    X86_COND_BE, STATUS))]>,
864                   Imp<[STATUS],[]>,  TB;
865
866 def CMOVA16rr : I<0x47, MRMSrcReg,       // if >u, R16 = R16
867                   (ops R16:$dst, R16:$src1, R16:$src2),
868                   "cmova {$src2, $dst|$dst, $src2}",
869                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
870                                    X86_COND_A, STATUS))]>,
871                   Imp<[STATUS],[]>,  TB, OpSize;
872 def CMOVA16rm : I<0x47, MRMSrcMem,       // if >u, R16 = [mem16]
873                   (ops R16:$dst, R16:$src1, i16mem:$src2),
874                   "cmova {$src2, $dst|$dst, $src2}",
875                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
876                                    X86_COND_A, STATUS))]>,
877                   Imp<[STATUS],[]>,  TB, OpSize;
878 def CMOVA32rr : I<0x47, MRMSrcReg,       // if >u, R32 = R32
879                   (ops R32:$dst, R32:$src1, R32:$src2),
880                   "cmova {$src2, $dst|$dst, $src2}",
881                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
882                                    X86_COND_A, STATUS))]>,
883                   Imp<[STATUS],[]>,  TB;
884 def CMOVA32rm : I<0x47, MRMSrcMem,       // if >u, R32 = [mem32]
885                   (ops R32:$dst, R32:$src1, i32mem:$src2),
886                   "cmova {$src2, $dst|$dst, $src2}",
887                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
888                                    X86_COND_A, STATUS))]>,
889                   Imp<[STATUS],[]>,  TB;
890
891 def CMOVL16rr : I<0x4C, MRMSrcReg,       // if <s, R16 = R16
892                   (ops R16:$dst, R16:$src1, R16:$src2),
893                   "cmovl {$src2, $dst|$dst, $src2}",
894                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
895                                    X86_COND_L, STATUS))]>,
896                   Imp<[STATUS],[]>,  TB, OpSize;
897 def CMOVL16rm : I<0x4C, MRMSrcMem,       // if <s, R16 = [mem16]
898                   (ops R16:$dst, R16:$src1, i16mem:$src2),
899                   "cmovl {$src2, $dst|$dst, $src2}",
900                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
901                                    X86_COND_L, STATUS))]>,
902                   Imp<[STATUS],[]>,  TB, OpSize;
903 def CMOVL32rr : I<0x4C, MRMSrcReg,       // if <s, R32 = R32
904                   (ops R32:$dst, R32:$src1, R32:$src2),
905                   "cmovl {$src2, $dst|$dst, $src2}",
906                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
907                                    X86_COND_L, STATUS))]>,
908                   Imp<[STATUS],[]>,  TB;
909 def CMOVL32rm : I<0x4C, MRMSrcMem,       // if <s, R32 = [mem32]
910                   (ops R32:$dst, R32:$src1, i32mem:$src2),
911                   "cmovl {$src2, $dst|$dst, $src2}",
912                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
913                                    X86_COND_L, STATUS))]>,
914                   Imp<[STATUS],[]>,  TB;
915
916 def CMOVGE16rr: I<0x4D, MRMSrcReg,       // if >=s, R16 = R16
917                   (ops R16:$dst, R16:$src1, R16:$src2),
918                   "cmovge {$src2, $dst|$dst, $src2}",
919                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
920                                    X86_COND_GE, STATUS))]>,
921                   Imp<[STATUS],[]>,  TB, OpSize;
922 def CMOVGE16rm: I<0x4D, MRMSrcMem,       // if >=s, R16 = [mem16]
923                   (ops R16:$dst, R16:$src1, i16mem:$src2),
924                   "cmovge {$src2, $dst|$dst, $src2}",
925                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
926                                    X86_COND_GE, STATUS))]>,
927                   Imp<[STATUS],[]>,  TB, OpSize;
928 def CMOVGE32rr: I<0x4D, MRMSrcReg,       // if >=s, R32 = R32
929                   (ops R32:$dst, R32:$src1, R32:$src2),
930                   "cmovge {$src2, $dst|$dst, $src2}",
931                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
932                                    X86_COND_GE, STATUS))]>,
933                   Imp<[STATUS],[]>,  TB;
934 def CMOVGE32rm: I<0x4D, MRMSrcMem,       // if >=s, R32 = [mem32]
935                   (ops R32:$dst, R32:$src1, i32mem:$src2),
936                   "cmovge {$src2, $dst|$dst, $src2}",
937                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
938                                    X86_COND_GE, STATUS))]>,
939                   Imp<[STATUS],[]>,  TB;
940
941 def CMOVLE16rr: I<0x4E, MRMSrcReg,       // if <=s, R16 = R16
942                   (ops R16:$dst, R16:$src1, R16:$src2),
943                   "cmovle {$src2, $dst|$dst, $src2}",
944                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
945                                    X86_COND_LE, STATUS))]>,
946                   Imp<[STATUS],[]>,  TB, OpSize;
947 def CMOVLE16rm: I<0x4E, MRMSrcMem,       // if <=s, R16 = [mem16]
948                   (ops R16:$dst, R16:$src1, i16mem:$src2),
949                   "cmovle {$src2, $dst|$dst, $src2}",
950                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
951                                    X86_COND_LE, STATUS))]>,
952                   Imp<[STATUS],[]>,  TB, OpSize;
953 def CMOVLE32rr: I<0x4E, MRMSrcReg,       // if <=s, R32 = R32
954                   (ops R32:$dst, R32:$src1, R32:$src2),
955                   "cmovle {$src2, $dst|$dst, $src2}",
956                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
957                                    X86_COND_LE, STATUS))]>,
958                   Imp<[STATUS],[]>,  TB;
959 def CMOVLE32rm: I<0x4E, MRMSrcMem,       // if <=s, R32 = [mem32]
960                   (ops R32:$dst, R32:$src1, i32mem:$src2),
961                   "cmovle {$src2, $dst|$dst, $src2}",
962                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
963                                    X86_COND_LE, STATUS))]>,
964                   Imp<[STATUS],[]>,  TB;
965
966 def CMOVG16rr : I<0x4F, MRMSrcReg,       // if >s, R16 = R16
967                   (ops R16:$dst, R16:$src1, R16:$src2),
968                   "cmovg {$src2, $dst|$dst, $src2}",
969                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
970                                    X86_COND_G, STATUS))]>,
971                   Imp<[STATUS],[]>,  TB, OpSize;
972 def CMOVG16rm : I<0x4F, MRMSrcMem,       // if >s, R16 = [mem16]
973                   (ops R16:$dst, R16:$src1, i16mem:$src2),
974                   "cmovg {$src2, $dst|$dst, $src2}",
975                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
976                                    X86_COND_G, STATUS))]>,
977                   Imp<[STATUS],[]>,  TB, OpSize;
978 def CMOVG32rr : I<0x4F, MRMSrcReg,       // if >s, R32 = R32
979                   (ops R32:$dst, R32:$src1, R32:$src2),
980                   "cmovg {$src2, $dst|$dst, $src2}",
981                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
982                                    X86_COND_G, STATUS))]>,
983                   Imp<[STATUS],[]>,  TB;
984 def CMOVG32rm : I<0x4F, MRMSrcMem,       // if >s, R32 = [mem32]
985                   (ops R32:$dst, R32:$src1, i32mem:$src2),
986                   "cmovg {$src2, $dst|$dst, $src2}",
987                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
988                                    X86_COND_G, STATUS))]>,
989                   Imp<[STATUS],[]>,  TB;
990
991 def CMOVS16rr : I<0x48, MRMSrcReg,       // if signed, R16 = R16
992                   (ops R16:$dst, R16:$src1, R16:$src2),
993                   "cmovs {$src2, $dst|$dst, $src2}",
994                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
995                                    X86_COND_S, STATUS))]>,
996                   Imp<[STATUS],[]>, TB, OpSize;
997 def CMOVS16rm : I<0x48, MRMSrcMem,       // if signed, R16 = [mem16]
998                   (ops R16:$dst, R16:$src1, i16mem:$src2),
999                   "cmovs {$src2, $dst|$dst, $src2}",
1000                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1001                                    X86_COND_S, STATUS))]>,
1002                   Imp<[STATUS],[]>, TB, OpSize;
1003 def CMOVS32rr : I<0x48, MRMSrcReg,       // if signed, R32 = R32
1004                   (ops R32:$dst, R32:$src1, R32:$src2),
1005                   "cmovs {$src2, $dst|$dst, $src2}",
1006                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1007                                    X86_COND_S, STATUS))]>,
1008                   Imp<[STATUS],[]>, TB;
1009 def CMOVS32rm : I<0x48, MRMSrcMem,       // if signed, R32 = [mem32]
1010                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1011                   "cmovs {$src2, $dst|$dst, $src2}",
1012                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1013                                    X86_COND_S, STATUS))]>,
1014                   Imp<[STATUS],[]>, TB;
1015
1016 def CMOVNS16rr: I<0x49, MRMSrcReg,       // if !signed, R16 = R16
1017                   (ops R16:$dst, R16:$src1, R16:$src2),
1018                   "cmovns {$src2, $dst|$dst, $src2}",
1019                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
1020                                    X86_COND_NS, STATUS))]>,
1021                   Imp<[STATUS],[]>, TB, OpSize;
1022 def CMOVNS16rm: I<0x49, MRMSrcMem,       // if !signed, R16 = [mem16]
1023                   (ops R16:$dst, R16:$src1, i16mem:$src2),
1024                   "cmovns {$src2, $dst|$dst, $src2}",
1025                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1026                                    X86_COND_NS, STATUS))]>,
1027                   Imp<[STATUS],[]>, TB, OpSize;
1028 def CMOVNS32rr: I<0x49, MRMSrcReg,       // if !signed, R32 = R32
1029                   (ops R32:$dst, R32:$src1, R32:$src2),
1030                   "cmovns {$src2, $dst|$dst, $src2}",
1031                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1032                                    X86_COND_NS, STATUS))]>,
1033                   Imp<[STATUS],[]>, TB;
1034 def CMOVNS32rm: I<0x49, MRMSrcMem,       // if !signed, R32 = [mem32]
1035                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1036                   "cmovns {$src2, $dst|$dst, $src2}",
1037                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1038                                    X86_COND_NS, STATUS))]>,
1039                   Imp<[STATUS],[]>, TB;
1040
1041 def CMOVP16rr : I<0x4A, MRMSrcReg,       // if parity, R16 = R16
1042                   (ops R16:$dst, R16:$src1, R16:$src2),
1043                   "cmovp {$src2, $dst|$dst, $src2}",
1044                   [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
1045                                    X86_COND_P, STATUS))]>,
1046                   Imp<[STATUS],[]>, TB, OpSize;
1047 def CMOVP16rm : I<0x4A, MRMSrcMem,       // if parity, R16 = [mem16]
1048                   (ops R16:$dst, R16:$src1, i16mem:$src2),
1049                   "cmovp {$src2, $dst|$dst, $src2}",
1050                   [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1051                                    X86_COND_P, STATUS))]>,
1052                   Imp<[STATUS],[]>, TB, OpSize;
1053 def CMOVP32rr : I<0x4A, MRMSrcReg,       // if parity, R32 = R32
1054                   (ops R32:$dst, R32:$src1, R32:$src2),
1055                   "cmovp {$src2, $dst|$dst, $src2}",
1056                   [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1057                                    X86_COND_P, STATUS))]>,
1058                   Imp<[STATUS],[]>, TB;
1059 def CMOVP32rm : I<0x4A, MRMSrcMem,       // if parity, R32 = [mem32]
1060                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1061                   "cmovp {$src2, $dst|$dst, $src2}",
1062                   [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1063                                    X86_COND_P, STATUS))]>,
1064                   Imp<[STATUS],[]>, TB;
1065
1066 def CMOVNP16rr : I<0x4B, MRMSrcReg,       // if !parity, R16 = R16
1067                   (ops R16:$dst, R16:$src1, R16:$src2),
1068                   "cmovnp {$src2, $dst|$dst, $src2}",
1069                    [(set R16:$dst, (X86cmov R16:$src1, R16:$src2,
1070                                     X86_COND_NP, STATUS))]>,
1071                   Imp<[STATUS],[]>, TB, OpSize;
1072 def CMOVNP16rm : I<0x4B, MRMSrcMem,       // if !parity, R16 = [mem16]
1073                   (ops R16:$dst, R16:$src1, i16mem:$src2),
1074                   "cmovnp {$src2, $dst|$dst, $src2}",
1075                    [(set R16:$dst, (X86cmov R16:$src1, (loadi16 addr:$src2),
1076                                     X86_COND_NP, STATUS))]>,
1077                   Imp<[STATUS],[]>, TB, OpSize;
1078 def CMOVNP32rr : I<0x4B, MRMSrcReg,       // if !parity, R32 = R32
1079                   (ops R32:$dst, R32:$src1, R32:$src2),
1080                   "cmovnp {$src2, $dst|$dst, $src2}",
1081                    [(set R32:$dst, (X86cmov R32:$src1, R32:$src2,
1082                                     X86_COND_NP, STATUS))]>,
1083                   Imp<[STATUS],[]>, TB;
1084 def CMOVNP32rm : I<0x4B, MRMSrcMem,       // if !parity, R32 = [mem32]
1085                   (ops R32:$dst, R32:$src1, i32mem:$src2),
1086                   "cmovnp {$src2, $dst|$dst, $src2}",
1087                    [(set R32:$dst, (X86cmov R32:$src1, (loadi32 addr:$src2),
1088                                    X86_COND_NP, STATUS))]>,
1089                   Imp<[STATUS],[]>, TB;
1090
1091
1092 // unary instructions
1093 def NEG8r  : I<0xF6, MRM3r, (ops R8 :$dst, R8 :$src), "neg{b} $dst",
1094                [(set R8:$dst, (ineg R8:$src))]>;
1095 def NEG16r : I<0xF7, MRM3r, (ops R16:$dst, R16:$src), "neg{w} $dst",
1096                [(set R16:$dst, (ineg R16:$src))]>, OpSize;
1097 def NEG32r : I<0xF7, MRM3r, (ops R32:$dst, R32:$src), "neg{l} $dst",
1098                [(set R32:$dst, (ineg R32:$src))]>;
1099 let isTwoAddress = 0 in {
1100   def NEG8m  : I<0xF6, MRM3m, (ops i8mem :$dst), "neg{b} $dst",
1101                  [(store (ineg (loadi8 addr:$dst)), addr:$dst)]>;
1102   def NEG16m : I<0xF7, MRM3m, (ops i16mem:$dst), "neg{w} $dst",
1103                  [(store (ineg (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1104   def NEG32m : I<0xF7, MRM3m, (ops i32mem:$dst), "neg{l} $dst",
1105                  [(store (ineg (loadi32 addr:$dst)), addr:$dst)]>;
1106
1107 }
1108
1109 def NOT8r  : I<0xF6, MRM2r, (ops R8 :$dst, R8 :$src), "not{b} $dst",
1110                [(set R8:$dst, (not R8:$src))]>;
1111 def NOT16r : I<0xF7, MRM2r, (ops R16:$dst, R16:$src), "not{w} $dst",
1112                [(set R16:$dst, (not R16:$src))]>, OpSize;
1113 def NOT32r : I<0xF7, MRM2r, (ops R32:$dst, R32:$src), "not{l} $dst",
1114                [(set R32:$dst, (not R32:$src))]>;
1115 let isTwoAddress = 0 in {
1116   def NOT8m  : I<0xF6, MRM2m, (ops i8mem :$dst), "not{b} $dst",
1117                  [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
1118   def NOT16m : I<0xF7, MRM2m, (ops i16mem:$dst), "not{w} $dst",
1119                  [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1120   def NOT32m : I<0xF7, MRM2m, (ops i32mem:$dst), "not{l} $dst",
1121                  [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
1122 }
1123
1124 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
1125 def INC8r  : I<0xFE, MRM0r, (ops R8 :$dst, R8 :$src), "inc{b} $dst",
1126                [(set R8:$dst, (add R8:$src, 1))]>;
1127 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1128 def INC16r : I<0xFF, MRM0r, (ops R16:$dst, R16:$src), "inc{w} $dst",
1129                [(set R16:$dst, (add R16:$src, 1))]>, OpSize;
1130 def INC32r : I<0xFF, MRM0r, (ops R32:$dst, R32:$src), "inc{l} $dst",
1131                [(set R32:$dst, (add R32:$src, 1))]>;
1132 }
1133 let isTwoAddress = 0 in {
1134   def INC8m  : I<0xFE, MRM0m, (ops i8mem :$dst), "inc{b} $dst",
1135                [(store (add (loadi8 addr:$dst), 1), addr:$dst)]>;
1136   def INC16m : I<0xFF, MRM0m, (ops i16mem:$dst), "inc{w} $dst",
1137                [(store (add (loadi16 addr:$dst), 1), addr:$dst)]>, OpSize;
1138   def INC32m : I<0xFF, MRM0m, (ops i32mem:$dst), "inc{l} $dst",
1139                [(store (add (loadi32 addr:$dst), 1), addr:$dst)]>;
1140 }
1141
1142 def DEC8r  : I<0xFE, MRM1r, (ops R8 :$dst, R8 :$src), "dec{b} $dst",
1143                [(set R8:$dst, (add R8:$src, -1))]>;
1144 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1145 def DEC16r : I<0xFF, MRM1r, (ops R16:$dst, R16:$src), "dec{w} $dst",
1146                [(set R16:$dst, (add R16:$src, -1))]>, OpSize;
1147 def DEC32r : I<0xFF, MRM1r, (ops R32:$dst, R32:$src), "dec{l} $dst",
1148                [(set R32:$dst, (add R32:$src, -1))]>;
1149 }
1150
1151 let isTwoAddress = 0 in {
1152   def DEC8m  : I<0xFE, MRM1m, (ops i8mem :$dst), "dec{b} $dst",
1153                [(store (add (loadi8 addr:$dst), -1), addr:$dst)]>;
1154   def DEC16m : I<0xFF, MRM1m, (ops i16mem:$dst), "dec{w} $dst",
1155                [(store (add (loadi16 addr:$dst), -1), addr:$dst)]>, OpSize;
1156   def DEC32m : I<0xFF, MRM1m, (ops i32mem:$dst), "dec{l} $dst",
1157                [(store (add (loadi32 addr:$dst), -1), addr:$dst)]>;
1158 }
1159
1160 // Logical operators...
1161 let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
1162 def AND8rr   : I<0x20, MRMDestReg,
1163                 (ops R8 :$dst, R8 :$src1, R8 :$src2),
1164                 "and{b} {$src2, $dst|$dst, $src2}",
1165                 [(set R8:$dst, (and R8:$src1, R8:$src2))]>;
1166 def AND16rr  : I<0x21, MRMDestReg,
1167                  (ops R16:$dst, R16:$src1, R16:$src2),
1168                  "and{w} {$src2, $dst|$dst, $src2}",
1169                  [(set R16:$dst, (and R16:$src1, R16:$src2))]>, OpSize;
1170 def AND32rr  : I<0x21, MRMDestReg, 
1171                  (ops R32:$dst, R32:$src1, R32:$src2),
1172                  "and{l} {$src2, $dst|$dst, $src2}",
1173                  [(set R32:$dst, (and R32:$src1, R32:$src2))]>;
1174 }
1175
1176 def AND8rm   : I<0x22, MRMSrcMem, 
1177                  (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1178                  "and{b} {$src2, $dst|$dst, $src2}",
1179                 [(set R8:$dst, (and R8:$src1, (load addr:$src2)))]>;
1180 def AND16rm  : I<0x23, MRMSrcMem, 
1181                  (ops R16:$dst, R16:$src1, i16mem:$src2),
1182                  "and{w} {$src2, $dst|$dst, $src2}",
1183                 [(set R16:$dst, (and R16:$src1, (load addr:$src2)))]>, OpSize;
1184 def AND32rm  : I<0x23, MRMSrcMem,
1185                  (ops R32:$dst, R32:$src1, i32mem:$src2),
1186                  "and{l} {$src2, $dst|$dst, $src2}",
1187                 [(set R32:$dst, (and R32:$src1, (load addr:$src2)))]>;
1188
1189 def AND8ri   : Ii8<0x80, MRM4r, 
1190                    (ops R8 :$dst, R8 :$src1, i8imm :$src2),
1191                    "and{b} {$src2, $dst|$dst, $src2}",
1192                    [(set R8:$dst, (and R8:$src1, imm:$src2))]>;
1193 def AND16ri  : Ii16<0x81, MRM4r, 
1194                     (ops R16:$dst, R16:$src1, i16imm:$src2),
1195                     "and{w} {$src2, $dst|$dst, $src2}",
1196                     [(set R16:$dst, (and R16:$src1, imm:$src2))]>, OpSize;
1197 def AND32ri  : Ii32<0x81, MRM4r, 
1198                     (ops R32:$dst, R32:$src1, i32imm:$src2),
1199                     "and{l} {$src2, $dst|$dst, $src2}",
1200                     [(set R32:$dst, (and R32:$src1, imm:$src2))]>;
1201 def AND16ri8 : Ii8<0x83, MRM4r, 
1202                    (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1203                    "and{w} {$src2, $dst|$dst, $src2}",
1204                    [(set R16:$dst, (and R16:$src1, i16immSExt8:$src2))]>,
1205                    OpSize;
1206 def AND32ri8 : Ii8<0x83, MRM4r, 
1207                    (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1208                    "and{l} {$src2, $dst|$dst, $src2}",
1209                    [(set R32:$dst, (and R32:$src1, i32immSExt8:$src2))]>;
1210
1211 let isTwoAddress = 0 in {
1212   def AND8mr   : I<0x20, MRMDestMem,
1213                    (ops i8mem :$dst, R8 :$src),
1214                    "and{b} {$src, $dst|$dst, $src}",
1215                    [(store (and (load addr:$dst), R8:$src), addr:$dst)]>;
1216   def AND16mr  : I<0x21, MRMDestMem,
1217                    (ops i16mem:$dst, R16:$src),
1218                    "and{w} {$src, $dst|$dst, $src}",
1219                    [(store (and (load addr:$dst), R16:$src), addr:$dst)]>,
1220                    OpSize;
1221   def AND32mr  : I<0x21, MRMDestMem,
1222                    (ops i32mem:$dst, R32:$src),
1223                    "and{l} {$src, $dst|$dst, $src}",
1224                    [(store (and (load addr:$dst), R32:$src), addr:$dst)]>;
1225   def AND8mi   : Ii8<0x80, MRM4m,
1226                      (ops i8mem :$dst, i8imm :$src),
1227                      "and{b} {$src, $dst|$dst, $src}",
1228                       [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1229   def AND16mi  : Ii16<0x81, MRM4m,
1230                       (ops i16mem:$dst, i16imm:$src),
1231                       "and{w} {$src, $dst|$dst, $src}",
1232                       [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1233                       OpSize;
1234   def AND32mi  : Ii32<0x81, MRM4m,
1235                       (ops i32mem:$dst, i32imm:$src),
1236                       "and{l} {$src, $dst|$dst, $src}",
1237                       [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1238   def AND16mi8 : Ii8<0x83, MRM4m,
1239                      (ops i16mem:$dst, i16i8imm :$src),
1240                      "and{w} {$src, $dst|$dst, $src}",
1241                 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1242                      OpSize;
1243   def AND32mi8 : Ii8<0x83, MRM4m,
1244                      (ops i32mem:$dst, i32i8imm :$src),
1245                      "and{l} {$src, $dst|$dst, $src}",
1246                 [(store (add (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1247 }
1248
1249
1250 let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
1251 def OR8rr    : I<0x08, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
1252                  "or{b} {$src2, $dst|$dst, $src2}",
1253                  [(set R8:$dst, (or R8:$src1, R8:$src2))]>;
1254 def OR16rr   : I<0x09, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1255                  "or{w} {$src2, $dst|$dst, $src2}",
1256                  [(set R16:$dst, (or R16:$src1, R16:$src2))]>, OpSize;
1257 def OR32rr   : I<0x09, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1258                  "or{l} {$src2, $dst|$dst, $src2}",
1259                  [(set R32:$dst, (or R32:$src1, R32:$src2))]>;
1260 }
1261 def OR8rm    : I<0x0A, MRMSrcMem , (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1262                  "or{b} {$src2, $dst|$dst, $src2}",
1263                 [(set R8:$dst, (or R8:$src1, (load addr:$src2)))]>;
1264 def OR16rm   : I<0x0B, MRMSrcMem , (ops R16:$dst, R16:$src1, i16mem:$src2),
1265                  "or{w} {$src2, $dst|$dst, $src2}",
1266                 [(set R16:$dst, (or R16:$src1, (load addr:$src2)))]>, OpSize;
1267 def OR32rm   : I<0x0B, MRMSrcMem , (ops R32:$dst, R32:$src1, i32mem:$src2),
1268                  "or{l} {$src2, $dst|$dst, $src2}",
1269                 [(set R32:$dst, (or R32:$src1, (load addr:$src2)))]>;
1270
1271 def OR8ri    : Ii8 <0x80, MRM1r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1272                     "or{b} {$src2, $dst|$dst, $src2}",
1273                     [(set R8:$dst, (or R8:$src1, imm:$src2))]>;
1274 def OR16ri   : Ii16<0x81, MRM1r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1275                     "or{w} {$src2, $dst|$dst, $src2}", 
1276                     [(set R16:$dst, (or R16:$src1, imm:$src2))]>, OpSize;
1277 def OR32ri   : Ii32<0x81, MRM1r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1278                     "or{l} {$src2, $dst|$dst, $src2}",
1279                     [(set R32:$dst, (or R32:$src1, imm:$src2))]>;
1280
1281 def OR16ri8  : Ii8<0x83, MRM1r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1282                    "or{w} {$src2, $dst|$dst, $src2}",
1283                    [(set R16:$dst, (or R16:$src1, i16immSExt8:$src2))]>, OpSize;
1284 def OR32ri8  : Ii8<0x83, MRM1r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1285                    "or{l} {$src2, $dst|$dst, $src2}",
1286                    [(set R32:$dst, (or R32:$src1, i32immSExt8:$src2))]>;
1287 let isTwoAddress = 0 in {
1288   def OR8mr  : I<0x08, MRMDestMem, (ops i8mem:$dst, R8:$src),
1289                  "or{b} {$src, $dst|$dst, $src}",
1290                  [(store (or (load addr:$dst), R8:$src), addr:$dst)]>;
1291   def OR16mr : I<0x09, MRMDestMem, (ops i16mem:$dst, R16:$src),
1292                  "or{w} {$src, $dst|$dst, $src}",
1293                  [(store (or (load addr:$dst), R16:$src), addr:$dst)]>, OpSize;
1294   def OR32mr : I<0x09, MRMDestMem, (ops i32mem:$dst, R32:$src),
1295                  "or{l} {$src, $dst|$dst, $src}",
1296                  [(store (or (load addr:$dst), R32:$src), addr:$dst)]>;
1297   def OR8mi    : Ii8<0x80, MRM1m, (ops i8mem :$dst, i8imm:$src),
1298                  "or{b} {$src, $dst|$dst, $src}",
1299                  [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1300   def OR16mi   : Ii16<0x81, MRM1m, (ops i16mem:$dst, i16imm:$src),
1301                  "or{w} {$src, $dst|$dst, $src}",
1302                  [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1303                  OpSize;
1304   def OR32mi   : Ii32<0x81, MRM1m, (ops i32mem:$dst, i32imm:$src),
1305                  "or{l} {$src, $dst|$dst, $src}",
1306                  [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1307   def OR16mi8  : Ii8<0x83, MRM1m, (ops i16mem:$dst, i16i8imm:$src),
1308                  "or{w} {$src, $dst|$dst, $src}",
1309                  [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1310                      OpSize;
1311   def OR32mi8  : Ii8<0x83, MRM1m, (ops i32mem:$dst, i32i8imm:$src),
1312                  "or{l} {$src, $dst|$dst, $src}",
1313                  [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1314 }
1315
1316
1317 let isCommutable = 1 in {   // X = XOR Y, Z   --> X = XOR Z, Y
1318 def XOR8rr   : I<0x30, MRMDestReg,
1319                  (ops R8 :$dst, R8 :$src1, R8 :$src2),
1320                  "xor{b} {$src2, $dst|$dst, $src2}",
1321                  [(set R8:$dst, (xor R8:$src1, R8:$src2))]>;
1322 def XOR16rr  : I<0x31, MRMDestReg, 
1323                  (ops R16:$dst, R16:$src1, R16:$src2), 
1324                  "xor{w} {$src2, $dst|$dst, $src2}",
1325                  [(set R16:$dst, (xor R16:$src1, R16:$src2))]>, OpSize;
1326 def XOR32rr  : I<0x31, MRMDestReg, 
1327                  (ops R32:$dst, R32:$src1, R32:$src2), 
1328                  "xor{l} {$src2, $dst|$dst, $src2}",
1329                  [(set R32:$dst, (xor R32:$src1, R32:$src2))]>;
1330 }
1331
1332 def XOR8rm   : I<0x32, MRMSrcMem , 
1333                  (ops R8 :$dst, R8:$src1, i8mem :$src2), 
1334                  "xor{b} {$src2, $dst|$dst, $src2}",
1335                  [(set R8:$dst, (xor R8:$src1, (load addr:$src2)))]>;
1336 def XOR16rm  : I<0x33, MRMSrcMem , 
1337                  (ops R16:$dst, R16:$src1, i16mem:$src2), 
1338                  "xor{w} {$src2, $dst|$dst, $src2}",
1339                  [(set R16:$dst, (xor R16:$src1, (load addr:$src2)))]>, OpSize;
1340 def XOR32rm  : I<0x33, MRMSrcMem , 
1341                  (ops R32:$dst, R32:$src1, i32mem:$src2), 
1342                  "xor{l} {$src2, $dst|$dst, $src2}",
1343                  [(set R32:$dst, (xor R32:$src1, (load addr:$src2)))]>;
1344
1345 def XOR8ri   : Ii8<0x80, MRM6r, 
1346                    (ops R8:$dst, R8:$src1, i8imm:$src2), 
1347                    "xor{b} {$src2, $dst|$dst, $src2}",
1348                    [(set R8:$dst, (xor R8:$src1, imm:$src2))]>;
1349 def XOR16ri  : Ii16<0x81, MRM6r, 
1350                     (ops R16:$dst, R16:$src1, i16imm:$src2), 
1351                     "xor{w} {$src2, $dst|$dst, $src2}",
1352                     [(set R16:$dst, (xor R16:$src1, imm:$src2))]>, OpSize;
1353 def XOR32ri  : Ii32<0x81, MRM6r, 
1354                     (ops R32:$dst, R32:$src1, i32imm:$src2), 
1355                     "xor{l} {$src2, $dst|$dst, $src2}",
1356                     [(set R32:$dst, (xor R32:$src1, imm:$src2))]>;
1357 def XOR16ri8 : Ii8<0x83, MRM6r, 
1358                    (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1359                    "xor{w} {$src2, $dst|$dst, $src2}",
1360                    [(set R16:$dst, (xor R16:$src1, i16immSExt8:$src2))]>,
1361                    OpSize;
1362 def XOR32ri8 : Ii8<0x83, MRM6r, 
1363                    (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1364                    "xor{l} {$src2, $dst|$dst, $src2}",
1365                    [(set R32:$dst, (xor R32:$src1, i32immSExt8:$src2))]>;
1366 let isTwoAddress = 0 in {
1367   def XOR8mr   : I<0x30, MRMDestMem,
1368                    (ops i8mem :$dst, R8 :$src),
1369                    "xor{b} {$src, $dst|$dst, $src}",
1370                    [(store (xor (load addr:$dst), R8:$src), addr:$dst)]>;
1371   def XOR16mr  : I<0x31, MRMDestMem,
1372                    (ops i16mem:$dst, R16:$src),
1373                    "xor{w} {$src, $dst|$dst, $src}",
1374                    [(store (xor (load addr:$dst), R16:$src), addr:$dst)]>,
1375                    OpSize;
1376   def XOR32mr  : I<0x31, MRMDestMem,
1377                    (ops i32mem:$dst, R32:$src),
1378                    "xor{l} {$src, $dst|$dst, $src}",
1379                    [(store (xor (load addr:$dst), R32:$src), addr:$dst)]>;
1380   def XOR8mi   : Ii8<0x80, MRM6m,
1381                      (ops i8mem :$dst, i8imm :$src),
1382                      "xor{b} {$src, $dst|$dst, $src}",
1383                     [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst)]>;
1384   def XOR16mi  : Ii16<0x81, MRM6m,
1385                       (ops i16mem:$dst, i16imm:$src),
1386                       "xor{w} {$src, $dst|$dst, $src}",
1387                    [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst)]>,
1388                       OpSize;
1389   def XOR32mi  : Ii32<0x81, MRM6m,
1390                       (ops i32mem:$dst, i32imm:$src),
1391                       "xor{l} {$src, $dst|$dst, $src}",
1392                    [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst)]>;
1393   def XOR16mi8 : Ii8<0x83, MRM6m,
1394                      (ops i16mem:$dst, i16i8imm :$src),
1395                      "xor{w} {$src, $dst|$dst, $src}",
1396                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst)]>,
1397                      OpSize;
1398   def XOR32mi8 : Ii8<0x83, MRM6m,
1399                      (ops i32mem:$dst, i32i8imm :$src),
1400                      "xor{l} {$src, $dst|$dst, $src}",
1401                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst)]>;
1402 }
1403
1404 // Shift instructions
1405 def SHL8rCL  : I<0xD2, MRM4r, (ops R8 :$dst, R8 :$src),
1406                  "shl{b} {%cl, $dst|$dst, %CL}",
1407                  [(set R8:$dst, (shl R8:$src, CL))]>, Imp<[CL],[]>;
1408 def SHL16rCL : I<0xD3, MRM4r, (ops R16:$dst, R16:$src),
1409                  "shl{w} {%cl, $dst|$dst, %CL}",
1410                  [(set R16:$dst, (shl R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1411 def SHL32rCL : I<0xD3, MRM4r, (ops R32:$dst, R32:$src),
1412                  "shl{l} {%cl, $dst|$dst, %CL}",
1413                  [(set R32:$dst, (shl R32:$src, CL))]>, Imp<[CL],[]>;
1414
1415 def SHL8ri   : Ii8<0xC0, MRM4r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1416                    "shl{b} {$src2, $dst|$dst, $src2}",
1417                    [(set R8:$dst, (shl R8:$src1, (i8 imm:$src2)))]>;
1418 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1419 def SHL16ri  : Ii8<0xC1, MRM4r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1420                    "shl{w} {$src2, $dst|$dst, $src2}",
1421                    [(set R16:$dst, (shl R16:$src1, (i8 imm:$src2)))]>, OpSize;
1422 def SHL32ri  : Ii8<0xC1, MRM4r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1423                    "shl{l} {$src2, $dst|$dst, $src2}",
1424                    [(set R32:$dst, (shl R32:$src1, (i8 imm:$src2)))]>;
1425 }
1426
1427 let isTwoAddress = 0 in {
1428   def SHL8mCL  : I<0xD2, MRM4m, (ops i8mem :$dst),
1429                    "shl{b} {%cl, $dst|$dst, %CL}",
1430                    [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>,
1431                    Imp<[CL],[]>;
1432   def SHL16mCL : I<0xD3, MRM4m, (ops i16mem:$dst),
1433                    "shl{w} {%cl, $dst|$dst, %CL}",
1434                    [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>,
1435                    Imp<[CL],[]>, OpSize;
1436   def SHL32mCL : I<0xD3, MRM4m, (ops i32mem:$dst),
1437                    "shl{l} {%cl, $dst|$dst, %CL}",
1438                    [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>,
1439                    Imp<[CL],[]>;
1440   def SHL8mi   : Ii8<0xC0, MRM4m, (ops i8mem :$dst, i8imm:$src),
1441                      "shl{b} {$src, $dst|$dst, $src}",
1442                   [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1443   def SHL16mi  : Ii8<0xC1, MRM4m, (ops i16mem:$dst, i8imm:$src),
1444                      "shl{w} {$src, $dst|$dst, $src}",
1445                  [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1446                      OpSize;
1447   def SHL32mi  : Ii8<0xC1, MRM4m, (ops i32mem:$dst, i8imm:$src),
1448                      "shl{l} {$src, $dst|$dst, $src}",
1449                  [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1450 }
1451
1452 def SHR8rCL  : I<0xD2, MRM5r, (ops R8 :$dst, R8 :$src),
1453                  "shr{b} {%cl, $dst|$dst, %CL}",
1454                  [(set R8:$dst, (srl R8:$src, CL))]>, Imp<[CL],[]>;
1455 def SHR16rCL : I<0xD3, MRM5r, (ops R16:$dst, R16:$src),
1456                  "shr{w} {%cl, $dst|$dst, %CL}",
1457                  [(set R16:$dst, (srl R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1458 def SHR32rCL : I<0xD3, MRM5r, (ops R32:$dst, R32:$src),
1459                  "shr{l} {%cl, $dst|$dst, %CL}",
1460                  [(set R32:$dst, (srl R32:$src, CL))]>, Imp<[CL],[]>;
1461
1462 def SHR8ri   : Ii8<0xC0, MRM5r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1463                    "shr{b} {$src2, $dst|$dst, $src2}",
1464                    [(set R8:$dst, (srl R8:$src1, (i8 imm:$src2)))]>;
1465 def SHR16ri  : Ii8<0xC1, MRM5r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1466                    "shr{w} {$src2, $dst|$dst, $src2}",
1467                    [(set R16:$dst, (srl R16:$src1, (i8 imm:$src2)))]>, OpSize;
1468 def SHR32ri  : Ii8<0xC1, MRM5r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1469                    "shr{l} {$src2, $dst|$dst, $src2}",
1470                    [(set R32:$dst, (srl R32:$src1, (i8 imm:$src2)))]>;
1471
1472 let isTwoAddress = 0 in {
1473   def SHR8mCL  : I<0xD2, MRM5m, (ops i8mem :$dst),
1474                    "shr{b} {%cl, $dst|$dst, %CL}",
1475                    [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>,
1476                    Imp<[CL],[]>;
1477   def SHR16mCL : I<0xD3, MRM5m, (ops i16mem:$dst),
1478                    "shr{w} {%cl, $dst|$dst, %CL}",
1479                    [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
1480                    Imp<[CL],[]>, OpSize;
1481   def SHR32mCL : I<0xD3, MRM5m, (ops i32mem:$dst),
1482                    "shr{l} {%cl, $dst|$dst, %CL}",
1483                    [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>,
1484                    Imp<[CL],[]>;
1485   def SHR8mi   : Ii8<0xC0, MRM5m, (ops i8mem :$dst, i8imm:$src),
1486                      "shr{b} {$src, $dst|$dst, $src}",
1487                   [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1488   def SHR16mi  : Ii8<0xC1, MRM5m, (ops i16mem:$dst, i8imm:$src),
1489                      "shr{w} {$src, $dst|$dst, $src}",
1490                  [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1491                      OpSize;
1492   def SHR32mi  : Ii8<0xC1, MRM5m, (ops i32mem:$dst, i8imm:$src),
1493                      "shr{l} {$src, $dst|$dst, $src}",
1494                  [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1495 }
1496
1497 def SAR8rCL  : I<0xD2, MRM7r, (ops R8 :$dst, R8 :$src),
1498                  "sar{b} {%cl, $dst|$dst, %CL}",
1499                  [(set R8:$dst, (sra R8:$src, CL))]>, Imp<[CL],[]>;
1500 def SAR16rCL : I<0xD3, MRM7r, (ops R16:$dst, R16:$src),
1501                  "sar{w} {%cl, $dst|$dst, %CL}",
1502                  [(set R16:$dst, (sra R16:$src, CL))]>, Imp<[CL],[]>, OpSize;
1503 def SAR32rCL : I<0xD3, MRM7r, (ops R32:$dst, R32:$src),
1504                  "sar{l} {%cl, $dst|$dst, %CL}",
1505                  [(set R32:$dst, (sra R32:$src, CL))]>, Imp<[CL],[]>;
1506
1507 def SAR8ri   : Ii8<0xC0, MRM7r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1508                    "sar{b} {$src2, $dst|$dst, $src2}",
1509                    [(set R8:$dst, (sra R8:$src1, (i8 imm:$src2)))]>;
1510 def SAR16ri  : Ii8<0xC1, MRM7r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1511                    "sar{w} {$src2, $dst|$dst, $src2}",
1512                    [(set R16:$dst, (sra R16:$src1, (i8 imm:$src2)))]>,
1513                    OpSize;
1514 def SAR32ri  : Ii8<0xC1, MRM7r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1515                    "sar{l} {$src2, $dst|$dst, $src2}",
1516                    [(set R32:$dst, (sra R32:$src1, (i8 imm:$src2)))]>;
1517 let isTwoAddress = 0 in {
1518   def SAR8mCL  : I<0xD2, MRM7m, (ops i8mem :$dst),
1519                    "sar{b} {%cl, $dst|$dst, %CL}",
1520                    [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>,
1521                    Imp<[CL],[]>;
1522   def SAR16mCL : I<0xD3, MRM7m, (ops i16mem:$dst),
1523                    "sar{w} {%cl, $dst|$dst, %CL}",
1524                    [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>,
1525                    Imp<[CL],[]>, OpSize;
1526   def SAR32mCL : I<0xD3, MRM7m, (ops i32mem:$dst), 
1527                    "sar{l} {%cl, $dst|$dst, %CL}",
1528                    [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>,
1529                    Imp<[CL],[]>;
1530   def SAR8mi   : Ii8<0xC0, MRM7m, (ops i8mem :$dst, i8imm:$src),
1531                      "sar{b} {$src, $dst|$dst, $src}",
1532                   [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1533   def SAR16mi  : Ii8<0xC1, MRM7m, (ops i16mem:$dst, i8imm:$src),
1534                      "sar{w} {$src, $dst|$dst, $src}",
1535                  [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1536                      OpSize;
1537   def SAR32mi  : Ii8<0xC1, MRM7m, (ops i32mem:$dst, i8imm:$src),
1538                      "sar{l} {$src, $dst|$dst, $src}",
1539                  [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1540 }
1541
1542 // Rotate instructions
1543 // FIXME: provide shorter instructions when imm8 == 1
1544 def ROL8rCL  : I<0xD2, MRM0r, (ops R8 :$dst, R8 :$src),
1545                  "rol{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1546 def ROL16rCL : I<0xD3, MRM0r, (ops R16:$dst, R16:$src),
1547                  "rol{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1548 def ROL32rCL : I<0xD3, MRM0r, (ops R32:$dst, R32:$src),
1549                  "rol{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1550
1551 def ROL8ri   : Ii8<0xC0, MRM0r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1552                    "rol{b} {$src2, $dst|$dst, $src2}", []>;
1553 def ROL16ri  : Ii8<0xC1, MRM0r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1554                    "rol{w} {$src2, $dst|$dst, $src2}", []>, OpSize;
1555 def ROL32ri  : Ii8<0xC1, MRM0r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1556                    "rol{l} {$src2, $dst|$dst, $src2}", []>;
1557
1558 let isTwoAddress = 0 in {
1559   def ROL8mCL  : I<0xD2, MRM0m, (ops i8mem :$dst),
1560                    "rol{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1561   def ROL16mCL : I<0xD3, MRM0m, (ops i16mem:$dst),
1562                    "rol{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1563   def ROL32mCL : I<0xD3, MRM0m, (ops i32mem:$dst),
1564                    "rol{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1565   def ROL8mi   : Ii8<0xC0, MRM0m, (ops i8mem :$dst, i8imm:$src),
1566                      "rol{b} {$src, $dst|$dst, $src}", []>;
1567   def ROL16mi  : Ii8<0xC1, MRM0m, (ops i16mem:$dst, i8imm:$src),
1568                      "rol{w} {$src, $dst|$dst, $src}", []>, OpSize;
1569   def ROL32mi  : Ii8<0xC1, MRM0m, (ops i32mem:$dst, i8imm:$src),
1570                      "rol{l} {$src, $dst|$dst, $src}", []>;
1571 }
1572
1573 def ROR8rCL  : I<0xD2, MRM1r, (ops R8 :$dst, R8 :$src),
1574                  "ror{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1575 def ROR16rCL : I<0xD3, MRM1r, (ops R16:$dst, R16:$src),
1576                  "ror{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1577 def ROR32rCL : I<0xD3, MRM1r, (ops R32:$dst, R32:$src),
1578                  "ror{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1579
1580 def ROR8ri   : Ii8<0xC0, MRM1r, (ops R8 :$dst, R8 :$src1, i8imm:$src2),
1581                    "ror{b} {$src2, $dst|$dst, $src2}", []>;
1582 def ROR16ri  : Ii8<0xC1, MRM1r, (ops R16:$dst, R16:$src1, i8imm:$src2),
1583                    "ror{w} {$src2, $dst|$dst, $src2}", []>, OpSize;
1584 def ROR32ri  : Ii8<0xC1, MRM1r, (ops R32:$dst, R32:$src1, i8imm:$src2),
1585                    "ror{l} {$src2, $dst|$dst, $src2}", []>;
1586 let isTwoAddress = 0 in {
1587   def ROR8mCL  : I<0xD2, MRM1m, (ops i8mem :$dst),
1588                    "ror{b} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1589   def ROR16mCL : I<0xD3, MRM1m, (ops i16mem:$dst),
1590                    "ror{w} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>, OpSize;
1591   def ROR32mCL : I<0xD3, MRM1m, (ops i32mem:$dst), 
1592                    "ror{l} {%cl, $dst|$dst, %CL}", []>, Imp<[CL],[]>;
1593   def ROR8mi   : Ii8<0xC0, MRM1m, (ops i8mem :$dst, i8imm:$src),
1594                      "ror{b} {$src, $dst|$dst, $src}", []>;
1595   def ROR16mi  : Ii8<0xC1, MRM1m, (ops i16mem:$dst, i8imm:$src),
1596                      "ror{w} {$src, $dst|$dst, $src}", []>, OpSize;
1597   def ROR32mi  : Ii8<0xC1, MRM1m, (ops i32mem:$dst, i8imm:$src),
1598                      "ror{l} {$src, $dst|$dst, $src}", []>;
1599 }
1600
1601
1602
1603 // Double shift instructions (generalizations of rotate)
1604
1605 def SHLD32rrCL : I<0xA5, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1606                    "shld{l} {%cl, $src2, $dst|$dst, $src2, %CL}",
1607                    [(set R32:$dst, (X86shld R32:$src1, R32:$src2, CL))]>,
1608                    Imp<[CL],[]>, TB;
1609 def SHRD32rrCL : I<0xAD, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1610                    "shrd{l} {%cl, $src2, $dst|$dst, $src2, %CL}",
1611                    [(set R32:$dst, (X86shrd R32:$src1, R32:$src2, CL))]>,
1612                    Imp<[CL],[]>, TB;
1613 def SHLD16rrCL : I<0xA5, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1614                    "shld{w} {%cl, $src2, $dst|$dst, $src2, %CL}",
1615                    [(set R16:$dst, (X86shld R16:$src1, R16:$src2, CL))]>,
1616                    Imp<[CL],[]>, TB, OpSize;
1617 def SHRD16rrCL : I<0xAD, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1618                    "shrd{w} {%cl, $src2, $dst|$dst, $src2, %CL}",
1619                    [(set R16:$dst, (X86shrd R16:$src1, R16:$src2, CL))]>,
1620                    Imp<[CL],[]>, TB, OpSize;
1621
1622 let isCommutable = 1 in {  // These instructions commute to each other.
1623 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
1624                      (ops R32:$dst, R32:$src1, R32:$src2, i8imm:$src3),
1625                      "shld{l} {$src3, $src2, $dst|$dst, $src2, $src3}",
1626                      [(set R32:$dst, (X86shld R32:$src1, R32:$src2,
1627                                       (i8 imm:$src3)))]>,
1628                  TB;
1629 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
1630                      (ops R32:$dst, R32:$src1, R32:$src2, i8imm:$src3),
1631                      "shrd{l} {$src3, $src2, $dst|$dst, $src2, $src3}",
1632                      [(set R32:$dst, (X86shrd R32:$src1, R32:$src2,
1633                                       (i8 imm:$src3)))]>,
1634                  TB;
1635 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
1636                      (ops R16:$dst, R16:$src1, R16:$src2, i8imm:$src3),
1637                      "shld{w} {$src3, $src2, $dst|$dst, $src2, $src3}",
1638                      [(set R16:$dst, (X86shld R16:$src1, R16:$src2,
1639                                       (i8 imm:$src3)))]>,
1640                      TB, OpSize;
1641 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
1642                      (ops R16:$dst, R16:$src1, R16:$src2, i8imm:$src3),
1643                      "shrd{w} {$src3, $src2, $dst|$dst, $src2, $src3}",
1644                      [(set R16:$dst, (X86shrd R16:$src1, R16:$src2,
1645                                       (i8 imm:$src3)))]>,
1646                      TB, OpSize;
1647 }
1648
1649 let isTwoAddress = 0 in {
1650   def SHLD32mrCL : I<0xA5, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1651                      "shld{l} {%cl, $src2, $dst|$dst, $src2, %CL}",
1652                      [(store (X86shld (loadi32 addr:$dst), R32:$src2, CL),
1653                        addr:$dst)]>,
1654                      Imp<[CL],[]>, TB;
1655   def SHRD32mrCL : I<0xAD, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1656                     "shrd{l} {%cl, $src2, $dst|$dst, $src2, %CL}",
1657                     [(store (X86shrd (loadi32 addr:$dst), R32:$src2, CL),
1658                       addr:$dst)]>,
1659                     Imp<[CL],[]>, TB;
1660   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
1661                       (ops i32mem:$dst, R32:$src2, i8imm:$src3),
1662                       "shld{l} {$src3, $src2, $dst|$dst, $src2, $src3}",
1663                       [(store (X86shld (loadi32 addr:$dst), R32:$src2,
1664                                         (i8 imm:$src3)), addr:$dst)]>,
1665                       TB;
1666   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
1667                        (ops i32mem:$dst, R32:$src2, i8imm:$src3),
1668                        "shrd{l} {$src3, $src2, $dst|$dst, $src2, $src3}",
1669                        [(store (X86shrd (loadi32 addr:$dst), R32:$src2,
1670                                          (i8 imm:$src3)), addr:$dst)]>,
1671                        TB;
1672
1673   def SHLD16mrCL : I<0xA5, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1674                      "shld{w} {%cl, $src2, $dst|$dst, $src2, %CL}",
1675                      [(store (X86shld (loadi16 addr:$dst), R16:$src2, CL),
1676                        addr:$dst)]>,
1677                      Imp<[CL],[]>, TB, OpSize;
1678   def SHRD16mrCL : I<0xAD, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1679                     "shrd{w} {%cl, $src2, $dst|$dst, $src2, %CL}",
1680                     [(store (X86shrd (loadi16 addr:$dst), R16:$src2, CL),
1681                       addr:$dst)]>,
1682                     Imp<[CL],[]>, TB, OpSize;
1683   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
1684                       (ops i16mem:$dst, R16:$src2, i8imm:$src3),
1685                       "shld{w} {$src3, $src2, $dst|$dst, $src2, $src3}",
1686                       [(store (X86shld (loadi16 addr:$dst), R16:$src2,
1687                                         (i8 imm:$src3)), addr:$dst)]>,
1688                       TB, OpSize;
1689   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
1690                        (ops i16mem:$dst, R16:$src2, i8imm:$src3),
1691                        "shrd{w} {$src3, $src2, $dst|$dst, $src2, $src3}",
1692                       [(store (X86shrd (loadi16 addr:$dst), R16:$src2,
1693                                         (i8 imm:$src3)), addr:$dst)]>,
1694                        TB, OpSize;
1695 }
1696
1697
1698 // Arithmetic.
1699 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
1700 def ADD8rr   : I<0x00, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
1701                  "add{b} {$src2, $dst|$dst, $src2}",
1702                  [(set R8:$dst, (add R8:$src1, R8:$src2))]>;
1703 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1704 def ADD16rr  : I<0x01, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1705                  "add{w} {$src2, $dst|$dst, $src2}",
1706                  [(set R16:$dst, (add R16:$src1, R16:$src2))]>, OpSize;
1707 def ADD32rr  : I<0x01, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1708                  "add{l} {$src2, $dst|$dst, $src2}",
1709                  [(set R32:$dst, (add R32:$src1, R32:$src2))]>;
1710 } // end isConvertibleToThreeAddress
1711 } // end isCommutable
1712 def ADD8rm   : I<0x02, MRMSrcMem, (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1713                  "add{b} {$src2, $dst|$dst, $src2}",
1714                  [(set R8:$dst, (add R8:$src1, (load addr:$src2)))]>;
1715 def ADD16rm  : I<0x03, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
1716                  "add{w} {$src2, $dst|$dst, $src2}",
1717                  [(set R16:$dst, (add R16:$src1, (load addr:$src2)))]>, OpSize;
1718 def ADD32rm  : I<0x03, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1719                  "add{l} {$src2, $dst|$dst, $src2}",
1720                  [(set R32:$dst, (add R32:$src1, (load addr:$src2)))]>;
1721
1722 def ADD8ri   : Ii8<0x80, MRM0r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1723                    "add{b} {$src2, $dst|$dst, $src2}",
1724                    [(set R8:$dst, (add R8:$src1, imm:$src2))]>;
1725
1726 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1727 def ADD16ri  : Ii16<0x81, MRM0r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1728                     "add{w} {$src2, $dst|$dst, $src2}",
1729                     [(set R16:$dst, (add R16:$src1, imm:$src2))]>, OpSize;
1730 def ADD32ri  : Ii32<0x81, MRM0r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1731                     "add{l} {$src2, $dst|$dst, $src2}",
1732                     [(set R32:$dst, (add R32:$src1, imm:$src2))]>;
1733 }
1734
1735 // FIXME: move ADD16ri8 above ADD16ri to optimize for space.
1736 def ADD16ri8 : Ii8<0x83, MRM0r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1737                    "add{w} {$src2, $dst|$dst, $src2}",
1738                    [(set R16:$dst, (add R16:$src1, i16immSExt8:$src2))]>,
1739                    OpSize;
1740 def ADD32ri8 : Ii8<0x83, MRM0r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1741                    "add{l} {$src2, $dst|$dst, $src2}",
1742                    [(set R32:$dst, (add R32:$src1, i32immSExt8:$src2))]>;
1743
1744 let isTwoAddress = 0 in {
1745   def ADD8mr   : I<0x00, MRMDestMem, (ops i8mem :$dst, R8 :$src2),
1746                    "add{b} {$src2, $dst|$dst, $src2}",
1747                    [(store (add (load addr:$dst), R8:$src2), addr:$dst)]>;
1748   def ADD16mr  : I<0x01, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1749                    "add{w} {$src2, $dst|$dst, $src2}",
1750                    [(store (add (load addr:$dst), R16:$src2), addr:$dst)]>,
1751                    OpSize;
1752   def ADD32mr  : I<0x01, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1753                    "add{l} {$src2, $dst|$dst, $src2}",
1754                    [(store (add (load addr:$dst), R32:$src2), addr:$dst)]>;
1755   def ADD8mi   : Ii8<0x80, MRM0m, (ops i8mem :$dst, i8imm :$src2),
1756                      "add{b} {$src2, $dst|$dst, $src2}",
1757                    [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
1758   def ADD16mi  : Ii16<0x81, MRM0m, (ops i16mem:$dst, i16imm:$src2),
1759                       "add{w} {$src2, $dst|$dst, $src2}",
1760                   [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
1761                    OpSize;
1762   def ADD32mi  : Ii32<0x81, MRM0m, (ops i32mem:$dst, i32imm:$src2),
1763                       "add{l} {$src2, $dst|$dst, $src2}",
1764                   [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1765   def ADD16mi8 : Ii8<0x83, MRM0m, (ops i16mem:$dst, i16i8imm :$src2),
1766                      "add{w} {$src2, $dst|$dst, $src2}",
1767                 [(store (add (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1768                    OpSize;
1769   def ADD32mi8 : Ii8<0x83, MRM0m, (ops i32mem:$dst, i32i8imm :$src2),
1770                      "add{l} {$src2, $dst|$dst, $src2}",
1771                 [(store (add (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1772 }
1773
1774 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
1775 def ADC32rr  : I<0x11, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1776                  "adc{l} {$src2, $dst|$dst, $src2}",
1777                  [(set R32:$dst, (X86adc R32:$src1, R32:$src2))]>;
1778 }
1779 def ADC32rm  : I<0x13, MRMSrcMem , (ops R32:$dst, R32:$src1, i32mem:$src2),
1780                  "adc{l} {$src2, $dst|$dst, $src2}",
1781                  [(set R32:$dst, (X86adc R32:$src1, (load addr:$src2)))]>;
1782 def ADC32ri  : Ii32<0x81, MRM2r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1783                     "adc{l} {$src2, $dst|$dst, $src2}",
1784                  [(set R32:$dst, (X86adc R32:$src1, imm:$src2))]>;
1785 def ADC32ri8 : Ii8<0x83, MRM2r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1786                    "adc{l} {$src2, $dst|$dst, $src2}",
1787                  [(set R32:$dst, (X86adc R32:$src1, i32immSExt8:$src2))]>;
1788
1789 let isTwoAddress = 0 in {
1790   def ADC32mr  : I<0x11, MRMDestMem, (ops i32mem:$dst, R32:$src2),
1791                    "adc{l} {$src2, $dst|$dst, $src2}",
1792                    [(store (X86adc (load addr:$dst), R32:$src2), addr:$dst)]>;
1793   def ADC32mi  : Ii32<0x81, MRM2m, (ops i32mem:$dst, i32imm:$src2),
1794                       "adc{l} {$src2, $dst|$dst, $src2}",
1795                   [(store (X86adc (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1796   def ADC32mi8 : Ii8<0x83, MRM2m, (ops i32mem:$dst, i32i8imm :$src2),
1797                      "adc{l} {$src2, $dst|$dst, $src2}",
1798              [(store (X86adc (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1799 }
1800
1801 def SUB8rr   : I<0x28, MRMDestReg, (ops R8 :$dst, R8 :$src1, R8 :$src2),
1802                  "sub{b} {$src2, $dst|$dst, $src2}",
1803                  [(set R8:$dst, (sub R8:$src1, R8:$src2))]>;
1804 def SUB16rr  : I<0x29, MRMDestReg, (ops R16:$dst, R16:$src1, R16:$src2),
1805                  "sub{w} {$src2, $dst|$dst, $src2}",
1806                  [(set R16:$dst, (sub R16:$src1, R16:$src2))]>, OpSize;
1807 def SUB32rr  : I<0x29, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1808                  "sub{l} {$src2, $dst|$dst, $src2}",
1809                  [(set R32:$dst, (sub R32:$src1, R32:$src2))]>;
1810 def SUB8rm   : I<0x2A, MRMSrcMem, (ops R8 :$dst, R8 :$src1, i8mem :$src2),
1811                  "sub{b} {$src2, $dst|$dst, $src2}",
1812                  [(set R8:$dst, (sub R8:$src1, (load addr:$src2)))]>;
1813 def SUB16rm  : I<0x2B, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
1814                  "sub{w} {$src2, $dst|$dst, $src2}",
1815                  [(set R16:$dst, (sub R16:$src1, (load addr:$src2)))]>, OpSize;
1816 def SUB32rm  : I<0x2B, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1817                  "sub{l} {$src2, $dst|$dst, $src2}",
1818                  [(set R32:$dst, (sub R32:$src1, (load addr:$src2)))]>;
1819
1820 def SUB8ri   : Ii8 <0x80, MRM5r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1821                     "sub{b} {$src2, $dst|$dst, $src2}",
1822                     [(set R8:$dst, (sub R8:$src1, imm:$src2))]>;
1823 def SUB16ri  : Ii16<0x81, MRM5r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1824                     "sub{w} {$src2, $dst|$dst, $src2}",
1825                     [(set R16:$dst, (sub R16:$src1, imm:$src2))]>, OpSize;
1826 def SUB32ri  : Ii32<0x81, MRM5r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1827                     "sub{l} {$src2, $dst|$dst, $src2}",
1828                     [(set R32:$dst, (sub R32:$src1, imm:$src2))]>;
1829 def SUB16ri8 : Ii8<0x83, MRM5r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1830                    "sub{w} {$src2, $dst|$dst, $src2}",
1831                    [(set R16:$dst, (sub R16:$src1, i16immSExt8:$src2))]>,
1832                    OpSize;
1833 def SUB32ri8 : Ii8<0x83, MRM5r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1834                    "sub{l} {$src2, $dst|$dst, $src2}",
1835                    [(set R32:$dst, (sub R32:$src1, i32immSExt8:$src2))]>;
1836 let isTwoAddress = 0 in {
1837   def SUB8mr   : I<0x28, MRMDestMem, (ops i8mem :$dst, R8 :$src2),
1838                    "sub{b} {$src2, $dst|$dst, $src2}",
1839                    [(store (sub (load addr:$dst), R8:$src2), addr:$dst)]>;
1840   def SUB16mr  : I<0x29, MRMDestMem, (ops i16mem:$dst, R16:$src2),
1841                    "sub{w} {$src2, $dst|$dst, $src2}",
1842                    [(store (sub (load addr:$dst), R16:$src2), addr:$dst)]>,
1843                    OpSize;
1844   def SUB32mr  : I<0x29, MRMDestMem, (ops i32mem:$dst, R32:$src2), 
1845                    "sub{l} {$src2, $dst|$dst, $src2}",
1846                    [(store (sub (load addr:$dst), R32:$src2), addr:$dst)]>;
1847   def SUB8mi   : Ii8<0x80, MRM5m, (ops i8mem :$dst, i8imm:$src2), 
1848                      "sub{b} {$src2, $dst|$dst, $src2}",
1849                    [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
1850   def SUB16mi  : Ii16<0x81, MRM5m, (ops i16mem:$dst, i16imm:$src2), 
1851                       "sub{w} {$src2, $dst|$dst, $src2}",
1852                   [(store (sub (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
1853                    OpSize;
1854   def SUB32mi  : Ii32<0x81, MRM5m, (ops i32mem:$dst, i32imm:$src2), 
1855                       "sub{l} {$src2, $dst|$dst, $src2}",
1856                   [(store (sub (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1857   def SUB16mi8 : Ii8<0x83, MRM5m, (ops i16mem:$dst, i16i8imm :$src2), 
1858                      "sub{w} {$src2, $dst|$dst, $src2}",
1859                 [(store (sub (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1860                    OpSize;
1861   def SUB32mi8 : Ii8<0x83, MRM5m, (ops i32mem:$dst, i32i8imm :$src2), 
1862                      "sub{l} {$src2, $dst|$dst, $src2}",
1863                 [(store (sub (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1864 }
1865
1866 def SBB32rr    : I<0x19, MRMDestReg, (ops R32:$dst, R32:$src1, R32:$src2),
1867                   "sbb{l} {$src2, $dst|$dst, $src2}",
1868                   [(set R32:$dst, (X86sbb R32:$src1, R32:$src2))]>;
1869
1870 let isTwoAddress = 0 in {
1871   def SBB32mr  : I<0x19, MRMDestMem, (ops i32mem:$dst, R32:$src2), 
1872                    "sbb{l} {$src2, $dst|$dst, $src2}",
1873                    [(store (X86sbb (load addr:$dst), R32:$src2), addr:$dst)]>;
1874   def SBB8mi  : Ii32<0x80, MRM3m, (ops i8mem:$dst, i8imm:$src2), 
1875                       "sbb{b} {$src2, $dst|$dst, $src2}",
1876                    [(store (X86sbb (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
1877   def SBB16mi  : Ii32<0x81, MRM3m, (ops i16mem:$dst, i16imm:$src2), 
1878                       "sbb{w} {$src2, $dst|$dst, $src2}",
1879                   [(store (X86sbb (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
1880                      OpSize;
1881   def SBB32mi  : Ii32<0x81, MRM3m, (ops i32mem:$dst, i32imm:$src2), 
1882                       "sbb{l} {$src2, $dst|$dst, $src2}",
1883                   [(store (X86sbb (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
1884   def SBB16mi8 : Ii8<0x83, MRM3m, (ops i16mem:$dst, i16i8imm :$src2), 
1885                      "sbb{w} {$src2, $dst|$dst, $src2}",
1886              [(store (X86sbb (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
1887                      OpSize;
1888   def SBB32mi8 : Ii8<0x83, MRM3m, (ops i32mem:$dst, i32i8imm :$src2), 
1889                      "sbb{l} {$src2, $dst|$dst, $src2}",
1890              [(store (X86sbb (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
1891 }
1892 def SBB8ri   : Ii8<0x80, MRM3r, (ops R8:$dst, R8:$src1, i8imm:$src2),
1893                     "sbb{b} {$src2, $dst|$dst, $src2}",
1894                     [(set R8:$dst, (X86sbb R8:$src1, imm:$src2))]>;
1895 def SBB16ri  : Ii16<0x81, MRM3r, (ops R16:$dst, R16:$src1, i16imm:$src2),
1896                     "sbb{w} {$src2, $dst|$dst, $src2}",
1897                     [(set R16:$dst, (X86sbb R16:$src1, imm:$src2))]>, OpSize;
1898
1899 def SBB32rm  : I<0x1B, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1900                     "sbb{l} {$src2, $dst|$dst, $src2}",
1901                     [(set R32:$dst, (X86sbb R32:$src1, (load addr:$src2)))]>;
1902 def SBB32ri  : Ii32<0x81, MRM3r, (ops R32:$dst, R32:$src1, i32imm:$src2),
1903                     "sbb{l} {$src2, $dst|$dst, $src2}",
1904                     [(set R32:$dst, (X86sbb R32:$src1, imm:$src2))]>;
1905
1906 def SBB16ri8 : Ii8<0x83, MRM3r, (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1907                    "sbb{w} {$src2, $dst|$dst, $src2}",
1908                    [(set R16:$dst, (X86sbb R16:$src1, i16immSExt8:$src2))]>,
1909                    OpSize;
1910 def SBB32ri8 : Ii8<0x83, MRM3r, (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1911                    "sbb{l} {$src2, $dst|$dst, $src2}",
1912                    [(set R32:$dst, (X86sbb R32:$src1, i32immSExt8:$src2))]>;
1913
1914 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
1915 def IMUL16rr : I<0xAF, MRMSrcReg, (ops R16:$dst, R16:$src1, R16:$src2),
1916                  "imul{w} {$src2, $dst|$dst, $src2}",
1917                  [(set R16:$dst, (mul R16:$src1, R16:$src2))]>, TB, OpSize;
1918 def IMUL32rr : I<0xAF, MRMSrcReg, (ops R32:$dst, R32:$src1, R32:$src2),
1919                  "imul{l} {$src2, $dst|$dst, $src2}",
1920                  [(set R32:$dst, (mul R32:$src1, R32:$src2))]>, TB;
1921 }
1922 def IMUL16rm : I<0xAF, MRMSrcMem, (ops R16:$dst, R16:$src1, i16mem:$src2),
1923                  "imul{w} {$src2, $dst|$dst, $src2}",
1924                  [(set R16:$dst, (mul R16:$src1, (load addr:$src2)))]>,
1925                  TB, OpSize;
1926 def IMUL32rm : I<0xAF, MRMSrcMem, (ops R32:$dst, R32:$src1, i32mem:$src2),
1927                  "imul{l} {$src2, $dst|$dst, $src2}",
1928                  [(set R32:$dst, (mul R32:$src1, (load addr:$src2)))]>, TB;
1929
1930 } // end Two Address instructions
1931
1932 // Suprisingly enough, these are not two address instructions!
1933 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // R16 = R16*I16
1934                       (ops R16:$dst, R16:$src1, i16imm:$src2),
1935                       "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
1936                       [(set R16:$dst, (mul R16:$src1, imm:$src2))]>, OpSize;
1937 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // R32 = R32*I32
1938                       (ops R32:$dst, R32:$src1, i32imm:$src2),
1939                       "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
1940                       [(set R32:$dst, (mul R32:$src1, imm:$src2))]>;
1941 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // R16 = R16*I8
1942                      (ops R16:$dst, R16:$src1, i16i8imm:$src2),
1943                      "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
1944                      [(set R16:$dst, (mul R16:$src1, i16immSExt8:$src2))]>,
1945                      OpSize;
1946 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // R32 = R32*I8
1947                      (ops R32:$dst, R32:$src1, i32i8imm:$src2),
1948                      "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
1949                      [(set R32:$dst, (mul R32:$src1, i32immSExt8:$src2))]>;
1950
1951 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                      // R16 = [mem16]*I16
1952                       (ops R16:$dst, i16mem:$src1, i16imm:$src2),
1953                       "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
1954                       [(set R16:$dst, (mul (load addr:$src1), imm:$src2))]>,
1955                       OpSize;
1956 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                      // R32 = [mem32]*I32
1957                       (ops R32:$dst, i32mem:$src1, i32imm:$src2),
1958                       "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
1959                       [(set R32:$dst, (mul (load addr:$src1), imm:$src2))]>;
1960 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // R16 = [mem16]*I8
1961                      (ops R16:$dst, i16mem:$src1, i16i8imm :$src2),
1962                      "imul{w} {$src2, $src1, $dst|$dst, $src1, $src2}",
1963                   [(set R16:$dst, (mul (load addr:$src1), i16immSExt8:$src2))]>,
1964                      OpSize;
1965 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // R32 = [mem32]*I8
1966                      (ops R32:$dst, i32mem:$src1, i32i8imm: $src2),
1967                      "imul{l} {$src2, $src1, $dst|$dst, $src1, $src2}",
1968                   [(set R32:$dst, (mul (load addr:$src1), i32immSExt8:$src2))]>;
1969
1970 //===----------------------------------------------------------------------===//
1971 // Test instructions are just like AND, except they don't generate a result.
1972 //
1973 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
1974 def TEST8rr  : I<0x84, MRMDestReg, (ops R8:$src1, R8:$src2),
1975                  "test{b} {$src2, $src1|$src1, $src2}",
1976                  [(set STATUS, (X86test R8:$src1, R8:$src2))]>,
1977                Imp<[],[STATUS]>;
1978 def TEST16rr : I<0x85, MRMDestReg, (ops R16:$src1, R16:$src2),
1979                  "test{w} {$src2, $src1|$src1, $src2}",
1980                  [(set STATUS, (X86test R16:$src1, R16:$src2))]>,
1981                Imp<[],[STATUS]>, OpSize;
1982 def TEST32rr : I<0x85, MRMDestReg, (ops R32:$src1, R32:$src2),
1983                  "test{l} {$src2, $src1|$src1, $src2}",
1984                  [(set STATUS, (X86test R32:$src1, R32:$src2))]>,
1985                Imp<[],[STATUS]>;
1986 }
1987 def TEST8mr  : I<0x84, MRMDestMem, (ops i8mem :$src1, R8 :$src2),
1988                  "test{b} {$src2, $src1|$src1, $src2}",
1989                  [(set STATUS, (X86test (loadi8 addr:$src1), R8:$src2))]>,
1990                Imp<[],[STATUS]>;
1991 def TEST16mr : I<0x85, MRMDestMem, (ops i16mem:$src1, R16:$src2),
1992                  "test{w} {$src2, $src1|$src1, $src2}",
1993                  [(set STATUS, (X86test (loadi16 addr:$src1), R16:$src2))]>,
1994                Imp<[],[STATUS]>, OpSize;
1995 def TEST32mr : I<0x85, MRMDestMem, (ops i32mem:$src1, R32:$src2),
1996                  "test{l} {$src2, $src1|$src1, $src2}",
1997                  [(set STATUS, (X86test (loadi32 addr:$src1), R32:$src2))]>,
1998                Imp<[],[STATUS]>;
1999 def TEST8rm  : I<0x84, MRMSrcMem, (ops R8 :$src1, i8mem :$src2),
2000                  "test{b} {$src2, $src1|$src1, $src2}",
2001                  [(set STATUS, (X86test R8:$src1, (loadi8 addr:$src2)))]>,
2002                Imp<[],[STATUS]>;
2003 def TEST16rm : I<0x85, MRMSrcMem, (ops R16:$src1, i16mem:$src2),
2004                  "test{w} {$src2, $src1|$src1, $src2}",
2005                  [(set STATUS, (X86test R16:$src1, (loadi16 addr:$src2)))]>,
2006                Imp<[],[STATUS]>, OpSize;
2007 def TEST32rm : I<0x85, MRMSrcMem, (ops R32:$src1, i32mem:$src2),
2008                  "test{l} {$src2, $src1|$src1, $src2}",
2009                  [(set STATUS, (X86test R32:$src1, (loadi32 addr:$src2)))]>,
2010                Imp<[],[STATUS]>;
2011
2012 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = R8  & imm8
2013                     (ops R8:$src1, i8imm:$src2),
2014                     "test{b} {$src2, $src1|$src1, $src2}",
2015                     [(set STATUS, (X86test R8:$src1, imm:$src2))]>,
2016                    Imp<[],[STATUS]>;
2017 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = R16 & imm16
2018                     (ops R16:$src1, i16imm:$src2),
2019                     "test{w} {$src2, $src1|$src1, $src2}",
2020                     [(set STATUS, (X86test R16:$src1, imm:$src2))]>,
2021                    Imp<[],[STATUS]>, OpSize;
2022 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = R32 & imm32
2023                     (ops R32:$src1, i32imm:$src2),
2024                     "test{l} {$src2, $src1|$src1, $src2}",
2025                     [(set STATUS, (X86test R32:$src1, imm:$src2))]>,
2026                    Imp<[],[STATUS]>;
2027 def TEST8mi  : Ii8 <0xF6, MRM0m,                     // flags = [mem8]  & imm8
2028                     (ops i8mem:$src1, i8imm:$src2),
2029                     "test{b} {$src2, $src1|$src1, $src2}",
2030                     [(set STATUS, (X86test (loadi8 addr:$src1), imm:$src2))]>,
2031                    Imp<[],[STATUS]>;
2032 def TEST16mi : Ii16<0xF7, MRM0m,                     // flags = [mem16] & imm16
2033                     (ops i16mem:$src1, i16imm:$src2),
2034                     "test{w} {$src2, $src1|$src1, $src2}",
2035                     [(set STATUS, (X86test (loadi16 addr:$src1), imm:$src2))]>,
2036                    Imp<[],[STATUS]>, OpSize;
2037 def TEST32mi : Ii32<0xF7, MRM0m,                     // flags = [mem32] & imm32
2038                     (ops i32mem:$src1, i32imm:$src2),
2039                     "test{l} {$src2, $src1|$src1, $src2}",
2040                     [(set STATUS, (X86test (loadi32 addr:$src1), imm:$src2))]>,
2041                    Imp<[],[STATUS]>;
2042
2043
2044 // Condition code ops, incl. set if equal/not equal/...
2045 def SAHF     : I<0x9E, RawFrm, (ops), "sahf", []>, Imp<[AH],[]>;  // flags = AH
2046 def LAHF     : I<0x9F, RawFrm, (ops), "lahf", []>, Imp<[],[AH]>;  // AH = flags
2047
2048 def SETEr    : I<0x94, MRM0r, 
2049                  (ops R8   :$dst),
2050                  "sete $dst",
2051                  [(set R8:$dst, (X86setcc X86_COND_E, STATUS))]>,
2052                TB;                        // R8 = ==
2053 def SETEm    : I<0x94, MRM0m, 
2054                  (ops i8mem:$dst),
2055                  "sete $dst",
2056                  [(store (X86setcc X86_COND_E, STATUS), addr:$dst)]>,
2057                TB;                        // [mem8] = ==
2058 def SETNEr   : I<0x95, MRM0r, 
2059                  (ops R8   :$dst),
2060                  "setne $dst",
2061                  [(set R8:$dst, (X86setcc X86_COND_NE, STATUS))]>,
2062                TB;                        // R8 = !=
2063 def SETNEm   : I<0x95, MRM0m, 
2064                  (ops i8mem:$dst),
2065                  "setne $dst",
2066                  [(store (X86setcc X86_COND_NE, STATUS), addr:$dst)]>,
2067                TB;                        // [mem8] = !=
2068 def SETLr    : I<0x9C, MRM0r, 
2069                  (ops R8   :$dst),
2070                  "setl $dst",
2071                  [(set R8:$dst, (X86setcc X86_COND_L, STATUS))]>,
2072                TB;                        // R8 = <  signed
2073 def SETLm    : I<0x9C, MRM0m, 
2074                  (ops i8mem:$dst),
2075                  "setl $dst",
2076                  [(store (X86setcc X86_COND_L, STATUS), addr:$dst)]>,
2077                TB;                        // [mem8] = <  signed
2078 def SETGEr   : I<0x9D, MRM0r, 
2079                  (ops R8   :$dst),
2080                  "setge $dst",
2081                  [(set R8:$dst, (X86setcc X86_COND_GE, STATUS))]>,
2082                TB;                        // R8 = >= signed
2083 def SETGEm   : I<0x9D, MRM0m, 
2084                  (ops i8mem:$dst),
2085                  "setge $dst",
2086                  [(store (X86setcc X86_COND_GE, STATUS), addr:$dst)]>,
2087                TB;                        // [mem8] = >= signed
2088 def SETLEr   : I<0x9E, MRM0r, 
2089                  (ops R8   :$dst),
2090                  "setle $dst",
2091                  [(set R8:$dst, (X86setcc X86_COND_LE, STATUS))]>,
2092                TB;                        // R8 = <= signed
2093 def SETLEm   : I<0x9E, MRM0m, 
2094                  (ops i8mem:$dst),
2095                  "setle $dst",
2096                  [(store (X86setcc X86_COND_LE, STATUS), addr:$dst)]>,
2097                TB;                        // [mem8] = <= signed
2098 def SETGr    : I<0x9F, MRM0r, 
2099                  (ops R8   :$dst),
2100                  "setg $dst",
2101                  [(set R8:$dst, (X86setcc X86_COND_G, STATUS))]>,
2102                TB;                        // R8 = >  signed
2103 def SETGm    : I<0x9F, MRM0m, 
2104                  (ops i8mem:$dst),
2105                  "setg $dst",
2106                  [(store (X86setcc X86_COND_G, STATUS), addr:$dst)]>,
2107                TB;                        // [mem8] = >  signed
2108
2109 def SETBr    : I<0x92, MRM0r,
2110                  (ops R8   :$dst),
2111                  "setb $dst",
2112                  [(set R8:$dst, (X86setcc X86_COND_B, STATUS))]>,
2113                TB;                        // R8 = <  unsign
2114 def SETBm    : I<0x92, MRM0m,
2115                  (ops i8mem:$dst),
2116                  "setb $dst",
2117                  [(store (X86setcc X86_COND_B, STATUS), addr:$dst)]>,
2118                TB;                        // [mem8] = <  unsign
2119 def SETAEr   : I<0x93, MRM0r, 
2120                  (ops R8   :$dst),
2121                  "setae $dst",
2122                  [(set R8:$dst, (X86setcc X86_COND_AE, STATUS))]>,
2123                TB;                        // R8 = >= unsign
2124 def SETAEm   : I<0x93, MRM0m, 
2125                  (ops i8mem:$dst),
2126                  "setae $dst",
2127                  [(store (X86setcc X86_COND_AE, STATUS), addr:$dst)]>,
2128                TB;                        // [mem8] = >= unsign
2129 def SETBEr   : I<0x96, MRM0r, 
2130                  (ops R8   :$dst),
2131                  "setbe $dst",
2132                  [(set R8:$dst, (X86setcc X86_COND_BE, STATUS))]>,
2133                TB;                        // R8 = <= unsign
2134 def SETBEm   : I<0x96, MRM0m, 
2135                  (ops i8mem:$dst),
2136                  "setbe $dst",
2137                  [(store (X86setcc X86_COND_BE, STATUS), addr:$dst)]>,
2138                TB;                        // [mem8] = <= unsign
2139 def SETAr    : I<0x97, MRM0r, 
2140                  (ops R8   :$dst),
2141                  "seta $dst",
2142                  [(set R8:$dst, (X86setcc X86_COND_A, STATUS))]>,
2143                TB;                        // R8 = >  signed
2144 def SETAm    : I<0x97, MRM0m, 
2145                  (ops i8mem:$dst),
2146                  "seta $dst",
2147                  [(store (X86setcc X86_COND_A, STATUS), addr:$dst)]>,
2148                TB;                        // [mem8] = >  signed
2149
2150 def SETSr    : I<0x98, MRM0r, 
2151                  (ops R8   :$dst),
2152                  "sets $dst",
2153                  [(set R8:$dst, (X86setcc X86_COND_S, STATUS))]>,
2154                TB;                        // R8 = <sign bit>
2155 def SETSm    : I<0x98, MRM0m, 
2156                  (ops i8mem:$dst),
2157                  "sets $dst",
2158                  [(store (X86setcc X86_COND_S, STATUS), addr:$dst)]>,
2159                TB;                        // [mem8] = <sign bit>
2160 def SETNSr   : I<0x99, MRM0r, 
2161                  (ops R8   :$dst),
2162                  "setns $dst",
2163                  [(set R8:$dst, (X86setcc X86_COND_NS, STATUS))]>,
2164                TB;                        // R8 = !<sign bit>
2165 def SETNSm   : I<0x99, MRM0m, 
2166                  (ops i8mem:$dst),
2167                  "setns $dst",
2168                  [(store (X86setcc X86_COND_NS, STATUS), addr:$dst)]>,
2169                TB;                        // [mem8] = !<sign bit>
2170 def SETPr    : I<0x9A, MRM0r, 
2171                  (ops R8   :$dst),
2172                  "setp $dst",
2173                  [(set R8:$dst, (X86setcc X86_COND_P, STATUS))]>,
2174                TB;                        // R8 = parity
2175 def SETPm    : I<0x9A, MRM0m, 
2176                  (ops i8mem:$dst),
2177                  "setp $dst",
2178                  [(store (X86setcc X86_COND_P, STATUS), addr:$dst)]>,
2179                TB;                        // [mem8] = parity
2180 def SETNPr   : I<0x9B, MRM0r, 
2181                  (ops R8   :$dst),
2182                  "setnp $dst",
2183                  [(set R8:$dst, (X86setcc X86_COND_NP, STATUS))]>,
2184                TB;                        // R8 = not parity
2185 def SETNPm   : I<0x9B, MRM0m, 
2186                  (ops i8mem:$dst),
2187                  "setnp $dst",
2188                  [(store (X86setcc X86_COND_NP, STATUS), addr:$dst)]>,
2189                TB;                        // [mem8] = not parity
2190
2191 // Integer comparisons
2192 def CMP8rr  : I<0x38, MRMDestReg,
2193                 (ops R8 :$src1, R8 :$src2),
2194                 "cmp{b} {$src2, $src1|$src1, $src2}",
2195                 [(set STATUS, (X86cmp R8:$src1, R8:$src2))]>,
2196               Imp<[],[STATUS]>;
2197 def CMP16rr : I<0x39, MRMDestReg,
2198                 (ops R16:$src1, R16:$src2),
2199                 "cmp{w} {$src2, $src1|$src1, $src2}",
2200                 [(set STATUS, (X86cmp R16:$src1, R16:$src2))]>,
2201               Imp<[],[STATUS]>, OpSize;
2202 def CMP32rr : I<0x39, MRMDestReg,
2203                 (ops R32:$src1, R32:$src2),
2204                 "cmp{l} {$src2, $src1|$src1, $src2}",
2205                 [(set STATUS, (X86cmp R32:$src1, R32:$src2))]>,
2206               Imp<[],[STATUS]>;
2207 def CMP8mr  : I<0x38, MRMDestMem,
2208                 (ops i8mem :$src1, R8 :$src2),
2209                 "cmp{b} {$src2, $src1|$src1, $src2}",
2210                 [(set STATUS, (X86cmp (loadi8 addr:$src1), R8:$src2))]>,
2211               Imp<[],[STATUS]>;
2212 def CMP16mr : I<0x39, MRMDestMem,
2213                 (ops i16mem:$src1, R16:$src2),
2214                 "cmp{w} {$src2, $src1|$src1, $src2}",
2215                 [(set STATUS, (X86cmp (loadi16 addr:$src1), R16:$src2))]>,
2216               Imp<[],[STATUS]>, OpSize;
2217 def CMP32mr : I<0x39, MRMDestMem,
2218                 (ops i32mem:$src1, R32:$src2),
2219                 "cmp{l} {$src2, $src1|$src1, $src2}",
2220                 [(set STATUS, (X86cmp (loadi32 addr:$src1), R32:$src2))]>,
2221               Imp<[],[STATUS]>;
2222 def CMP8rm  : I<0x3A, MRMSrcMem,
2223                 (ops R8 :$src1, i8mem :$src2),
2224                 "cmp{b} {$src2, $src1|$src1, $src2}",
2225                 [(set STATUS, (X86cmp R8:$src1, (loadi8 addr:$src2)))]>,
2226               Imp<[],[STATUS]>;
2227 def CMP16rm : I<0x3B, MRMSrcMem,
2228                 (ops R16:$src1, i16mem:$src2),
2229                 "cmp{w} {$src2, $src1|$src1, $src2}",
2230                 [(set STATUS, (X86cmp R16:$src1, (loadi16 addr:$src2)))]>,
2231                 Imp<[],[STATUS]>, OpSize;
2232 def CMP32rm : I<0x3B, MRMSrcMem,
2233                 (ops R32:$src1, i32mem:$src2),
2234                 "cmp{l} {$src2, $src1|$src1, $src2}",
2235                 [(set STATUS, (X86cmp R32:$src1, (loadi32 addr:$src2)))]>,
2236               Imp<[],[STATUS]>;
2237 def CMP8ri  : Ii8<0x80, MRM7r,
2238                   (ops R8:$src1, i8imm:$src2),
2239                   "cmp{b} {$src2, $src1|$src1, $src2}",
2240                   [(set STATUS, (X86cmp R8:$src1, imm:$src2))]>,
2241               Imp<[],[STATUS]>;
2242 def CMP16ri : Ii16<0x81, MRM7r,
2243                    (ops R16:$src1, i16imm:$src2),
2244                    "cmp{w} {$src2, $src1|$src1, $src2}",
2245                    [(set STATUS, (X86cmp R16:$src1, imm:$src2))]>,
2246               Imp<[],[STATUS]>, OpSize;
2247 def CMP32ri : Ii32<0x81, MRM7r,
2248                    (ops R32:$src1, i32imm:$src2),
2249                    "cmp{l} {$src2, $src1|$src1, $src2}",
2250                    [(set STATUS, (X86cmp R32:$src1, imm:$src2))]>,
2251               Imp<[],[STATUS]>;
2252 def CMP8mi  : Ii8 <0x80, MRM7m,
2253                    (ops i8mem :$src1, i8imm :$src2),
2254                    "cmp{b} {$src2, $src1|$src1, $src2}",
2255                    [(set STATUS, (X86cmp (loadi8 addr:$src1), imm:$src2))]>,
2256               Imp<[],[STATUS]>;
2257 def CMP16mi : Ii16<0x81, MRM7m,
2258                    (ops i16mem:$src1, i16imm:$src2),
2259                    "cmp{w} {$src2, $src1|$src1, $src2}",
2260                    [(set STATUS, (X86cmp (loadi16 addr:$src1), imm:$src2))]>,
2261               Imp<[],[STATUS]>, OpSize;
2262 def CMP32mi : Ii32<0x81, MRM7m,
2263                    (ops i32mem:$src1, i32imm:$src2),
2264                    "cmp{l} {$src2, $src1|$src1, $src2}",
2265                    [(set STATUS, (X86cmp (loadi32 addr:$src1), imm:$src2))]>,
2266               Imp<[],[STATUS]>;
2267
2268 // Sign/Zero extenders
2269 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (ops R16:$dst, R8 :$src),
2270                    "movs{bw|x} {$src, $dst|$dst, $src}",
2271                    [(set R16:$dst, (sext R8:$src))]>, TB, OpSize;
2272 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (ops R16:$dst, i8mem :$src),
2273                    "movs{bw|x} {$src, $dst|$dst, $src}",
2274                    [(set R16:$dst, (sextloadi16i8 addr:$src))]>, TB, OpSize;
2275 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (ops R32:$dst, R8 :$src),
2276                    "movs{bl|x} {$src, $dst|$dst, $src}",
2277                    [(set R32:$dst, (sext R8:$src))]>, TB;
2278 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (ops R32:$dst, i8mem :$src),
2279                    "movs{bl|x} {$src, $dst|$dst, $src}",
2280                    [(set R32:$dst, (sextloadi32i8 addr:$src))]>, TB;
2281 def MOVSX32rr16: I<0xBF, MRMSrcReg, (ops R32:$dst, R16:$src),
2282                    "movs{wl|x} {$src, $dst|$dst, $src}",
2283                    [(set R32:$dst, (sext R16:$src))]>, TB;
2284 def MOVSX32rm16: I<0xBF, MRMSrcMem, (ops R32:$dst, i16mem:$src),
2285                    "movs{wl|x} {$src, $dst|$dst, $src}",
2286                    [(set R32:$dst, (sextloadi32i16 addr:$src))]>, TB;
2287
2288 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (ops R16:$dst, R8 :$src),
2289                    "movz{bw|x} {$src, $dst|$dst, $src}",
2290                    [(set R16:$dst, (zext R8:$src))]>, TB, OpSize;
2291 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (ops R16:$dst, i8mem :$src),
2292                    "movz{bw|x} {$src, $dst|$dst, $src}",
2293                    [(set R16:$dst, (zextloadi16i8 addr:$src))]>, TB, OpSize;
2294 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (ops R32:$dst, R8 :$src),
2295                    "movz{bl|x} {$src, $dst|$dst, $src}",
2296                    [(set R32:$dst, (zext R8:$src))]>, TB;
2297 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (ops R32:$dst, i8mem :$src),
2298                    "movz{bl|x} {$src, $dst|$dst, $src}",
2299                    [(set R32:$dst, (zextloadi32i8 addr:$src))]>, TB;
2300 def MOVZX32rr16: I<0xB7, MRMSrcReg, (ops R32:$dst, R16:$src),
2301                    "movz{wl|x} {$src, $dst|$dst, $src}",
2302                    [(set R32:$dst, (zext R16:$src))]>, TB;
2303 def MOVZX32rm16: I<0xB7, MRMSrcMem, (ops R32:$dst, i16mem:$src),
2304                    "movz{wl|x} {$src, $dst|$dst, $src}",
2305                    [(set R32:$dst, (zextloadi32i16 addr:$src))]>, TB;
2306
2307 //===----------------------------------------------------------------------===//
2308 // XMM Floating point support (requires SSE / SSE2)
2309 //===----------------------------------------------------------------------===//
2310
2311 def MOVSSrr : I<0x10, MRMSrcReg, (ops FR32:$dst, FR32:$src),
2312                 "movss {$src, $dst|$dst, $src}", []>,
2313               Requires<[HasSSE1]>, XS;
2314 def MOVSDrr : I<0x10, MRMSrcReg, (ops FR64:$dst, FR64:$src),
2315                 "movsd {$src, $dst|$dst, $src}", []>,
2316               Requires<[HasSSE2]>, XD;
2317
2318 def MOVSSrm : I<0x10, MRMSrcMem, (ops FR32:$dst, f32mem:$src),
2319                 "movss {$src, $dst|$dst, $src}",
2320                 [(set FR32:$dst, (loadf32 addr:$src))]>,
2321               Requires<[HasSSE1]>, XS;
2322 def MOVSSmr : I<0x11, MRMDestMem, (ops f32mem:$dst, FR32:$src),
2323                 "movss {$src, $dst|$dst, $src}",
2324                 [(store FR32:$src, addr:$dst)]>,
2325               Requires<[HasSSE1]>, XS;
2326 def MOVSDrm : I<0x10, MRMSrcMem, (ops FR64:$dst, f64mem:$src),
2327                 "movsd {$src, $dst|$dst, $src}",
2328                 [(set FR64:$dst, (loadf64 addr:$src))]>,
2329               Requires<[HasSSE2]>, XD;
2330 def MOVSDmr : I<0x11, MRMDestMem, (ops f64mem:$dst, FR64:$src),
2331                 "movsd {$src, $dst|$dst, $src}",
2332                 [(store FR64:$src, addr:$dst)]>,
2333               Requires<[HasSSE2]>, XD;
2334
2335 def CVTTSD2SIrr: I<0x2C, MRMSrcReg, (ops R32:$dst, FR64:$src),
2336                    "cvttsd2si {$src, $dst|$dst, $src}",
2337                    [(set R32:$dst, (fp_to_sint FR64:$src))]>,
2338                  Requires<[HasSSE2]>, XD;
2339 def CVTTSD2SIrm: I<0x2C, MRMSrcMem, (ops R32:$dst, f64mem:$src),
2340                    "cvttsd2si {$src, $dst|$dst, $src}",
2341                    [(set R32:$dst, (fp_to_sint (loadf64 addr:$src)))]>,
2342                  Requires<[HasSSE2]>, XD;
2343 def CVTTSS2SIrr: I<0x2C, MRMSrcReg, (ops R32:$dst, FR32:$src),
2344                    "cvttss2si {$src, $dst|$dst, $src}",
2345                    [(set R32:$dst, (fp_to_sint FR32:$src))]>,
2346                  Requires<[HasSSE1]>, XS;
2347 def CVTTSS2SIrm: I<0x2C, MRMSrcMem, (ops R32:$dst, f32mem:$src),
2348                    "cvttss2si {$src, $dst|$dst, $src}",
2349                    [(set R32:$dst, (fp_to_sint (loadf32 addr:$src)))]>,
2350                  Requires<[HasSSE1]>, XS;
2351 def CVTSD2SSrr: I<0x5A, MRMSrcReg, (ops FR32:$dst, FR64:$src),
2352                   "cvtsd2ss {$src, $dst|$dst, $src}",
2353                   [(set FR32:$dst, (fround FR64:$src))]>,
2354                 Requires<[HasSSE2]>, XS;
2355 def CVTSD2SSrm: I<0x5A, MRMSrcMem, (ops FR32:$dst, f64mem:$src), 
2356                   "cvtsd2ss {$src, $dst|$dst, $src}",
2357                   [(set FR32:$dst, (fround (loadf64 addr:$src)))]>,
2358                 Requires<[HasSSE2]>, XS;
2359 def CVTSS2SDrr: I<0x5A, MRMSrcReg, (ops FR64:$dst, FR32:$src),
2360                   "cvtss2sd {$src, $dst|$dst, $src}",
2361                   [(set FR64:$dst, (fextend FR32:$src))]>,
2362                 Requires<[HasSSE2]>, XD;
2363 def CVTSS2SDrm: I<0x5A, MRMSrcMem, (ops FR64:$dst, f32mem:$src),
2364                   "cvtss2sd {$src, $dst|$dst, $src}",
2365                   [(set FR64:$dst, (fextend (loadf32 addr:$src)))]>,
2366                 Requires<[HasSSE2]>, XD;
2367 def CVTSI2SSrr: I<0x2A, MRMSrcReg, (ops FR32:$dst, R32:$src),
2368                   "cvtsi2ss {$src, $dst|$dst, $src}",
2369                   [(set FR32:$dst, (sint_to_fp R32:$src))]>,
2370                 Requires<[HasSSE2]>, XS;
2371 def CVTSI2SSrm: I<0x2A, MRMSrcMem, (ops FR32:$dst, i32mem:$src),
2372                   "cvtsi2ss {$src, $dst|$dst, $src}",
2373                   [(set FR32:$dst, (sint_to_fp (loadi32 addr:$src)))]>,
2374                 Requires<[HasSSE2]>, XS;
2375 def CVTSI2SDrr: I<0x2A, MRMSrcReg, (ops FR64:$dst, R32:$src),
2376                   "cvtsi2sd {$src, $dst|$dst, $src}",
2377                   [(set FR64:$dst, (sint_to_fp R32:$src))]>,
2378                 Requires<[HasSSE2]>, XD;
2379 def CVTSI2SDrm: I<0x2A, MRMSrcMem, (ops FR64:$dst, i32mem:$src),
2380                   "cvtsi2sd {$src, $dst|$dst, $src}",
2381                   [(set FR64:$dst, (sint_to_fp (loadi32 addr:$src)))]>,
2382                 Requires<[HasSSE2]>, XD;
2383
2384 def SQRTSSrm : I<0x51, MRMSrcMem, (ops FR32:$dst, f32mem:$src),
2385                  "sqrtss {$src, $dst|$dst, $src}",
2386                  [(set FR32:$dst, (fsqrt (loadf32 addr:$src)))]>,
2387                Requires<[HasSSE1]>, XS;
2388 def SQRTSSrr : I<0x51, MRMSrcReg, (ops FR32:$dst, FR32:$src),
2389                  "sqrtss {$src, $dst|$dst, $src}",
2390                  [(set FR32:$dst, (fsqrt FR32:$src))]>,
2391                Requires<[HasSSE1]>, XS;
2392 def SQRTSDrm : I<0x51, MRMSrcMem, (ops FR64:$dst, f64mem:$src),
2393                  "sqrtsd {$src, $dst|$dst, $src}",
2394                  [(set FR64:$dst, (fsqrt (loadf64 addr:$src)))]>,
2395                Requires<[HasSSE2]>, XD;
2396 def SQRTSDrr : I<0x51, MRMSrcReg, (ops FR64:$dst, FR64:$src),
2397                  "sqrtsd {$src, $dst|$dst, $src}",
2398                  [(set FR64:$dst, (fsqrt FR64:$src))]>,
2399                Requires<[HasSSE2]>, XD;
2400
2401 def UCOMISDrr: I<0x2E, MRMSrcReg, (ops FR64:$src1, FR64:$src2),
2402                  "ucomisd {$src2, $src1|$src1, $src2}",
2403                  [(set STATUS, (X86cmp FR64:$src1, FR64:$src2))]>,
2404                Requires<[HasSSE2]>, TB, OpSize;
2405 def UCOMISDrm: I<0x2E, MRMSrcMem, (ops FR64:$src1, f64mem:$src2),
2406                  "ucomisd {$src2, $src1|$src1, $src2}",
2407                  [(set STATUS, (X86cmp FR64:$src1, (loadf64 addr:$src2)))]>,
2408                Imp<[],[STATUS]>, Requires<[HasSSE2]>, TB, OpSize;
2409 def UCOMISSrr: I<0x2E, MRMSrcReg, (ops FR32:$src1, FR32:$src2),
2410                  "ucomiss {$src2, $src1|$src1, $src2}",
2411                  [(set STATUS, (X86cmp FR32:$src1, FR32:$src2))]>,
2412                Imp<[],[STATUS]>, Requires<[HasSSE1]>, TB;
2413 def UCOMISSrm: I<0x2E, MRMSrcMem, (ops FR32:$src1, f32mem:$src2),
2414                  "ucomiss {$src2, $src1|$src1, $src2}",
2415                  [(set STATUS, (X86cmp FR32:$src1, (loadf32 addr:$src2)))]>,
2416                Imp<[],[STATUS]>, Requires<[HasSSE1]>, TB;
2417
2418 // Pseudo-instructions that map fld0 to xorps/xorpd for sse.
2419 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
2420 def FLD0SS : I<0x57, MRMSrcReg, (ops FR32:$dst),
2421                "xorps $dst, $dst", [(set FR32:$dst, fp32imm0)]>,
2422              Requires<[HasSSE1]>, TB;
2423 def FLD0SD : I<0x57, MRMSrcReg, (ops FR64:$dst),
2424                "xorpd $dst, $dst", [(set FR64:$dst, fp64imm0)]>,
2425              Requires<[HasSSE2]>, TB, OpSize;
2426
2427 let isTwoAddress = 1 in {
2428 // SSE Scalar Arithmetic
2429 let isCommutable = 1 in {
2430 def ADDSSrr : I<0x58, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2431                 "addss {$src2, $dst|$dst, $src2}",
2432                 [(set FR32:$dst, (fadd FR32:$src1, FR32:$src2))]>,
2433               Requires<[HasSSE1]>, XS;
2434 def ADDSDrr : I<0x58, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2435                 "addsd {$src2, $dst|$dst, $src2}",
2436                 [(set FR64:$dst, (fadd FR64:$src1, FR64:$src2))]>,
2437               Requires<[HasSSE2]>, XD;
2438 def MULSSrr : I<0x59, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2439                 "mulss {$src2, $dst|$dst, $src2}",
2440                 [(set FR32:$dst, (fmul FR32:$src1, FR32:$src2))]>,
2441               Requires<[HasSSE1]>, XS;
2442 def MULSDrr : I<0x59, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2443                 "mulsd {$src2, $dst|$dst, $src2}",
2444                 [(set FR64:$dst, (fmul FR64:$src1, FR64:$src2))]>,
2445               Requires<[HasSSE2]>, XD;
2446 }
2447
2448 def ADDSSrm : I<0x58, MRMSrcMem, (ops FR32:$dst, FR32:$src1, f32mem:$src2),
2449                 "addss {$src2, $dst|$dst, $src2}",
2450                 [(set FR32:$dst, (fadd FR32:$src1, (loadf32 addr:$src2)))]>,
2451               Requires<[HasSSE1]>, XS;
2452 def ADDSDrm : I<0x58, MRMSrcMem, (ops FR64:$dst, FR64:$src1, f64mem:$src2),
2453                 "addsd {$src2, $dst|$dst, $src2}",
2454                 [(set FR64:$dst, (fadd FR64:$src1, (loadf64 addr:$src2)))]>,
2455               Requires<[HasSSE2]>, XD;
2456 def MULSSrm : I<0x59, MRMSrcMem, (ops FR32:$dst, FR32:$src1, f32mem:$src2),
2457                 "mulss {$src2, $dst|$dst, $src2}",
2458                 [(set FR32:$dst, (fmul FR32:$src1, (loadf32 addr:$src2)))]>,
2459               Requires<[HasSSE1]>, XS;
2460 def MULSDrm : I<0x59, MRMSrcMem, (ops FR64:$dst, FR64:$src1, f64mem:$src2),
2461                 "mulsd {$src2, $dst|$dst, $src2}",
2462                 [(set FR64:$dst, (fmul FR64:$src1, (loadf64 addr:$src2)))]>,
2463               Requires<[HasSSE2]>, XD;
2464
2465 def DIVSSrr : I<0x5E, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2466                 "divss {$src2, $dst|$dst, $src2}",
2467                 [(set FR32:$dst, (fdiv FR32:$src1, FR32:$src2))]>,
2468               Requires<[HasSSE1]>, XS;
2469 def DIVSSrm : I<0x5E, MRMSrcMem, (ops FR32:$dst, FR32:$src1, f32mem:$src2),
2470                 "divss {$src2, $dst|$dst, $src2}",
2471                 [(set FR32:$dst, (fdiv FR32:$src1, (loadf32 addr:$src2)))]>,
2472               Requires<[HasSSE1]>, XS;
2473 def DIVSDrr : I<0x5E, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2474                 "divsd {$src2, $dst|$dst, $src2}",
2475                 [(set FR64:$dst, (fdiv FR64:$src1, FR64:$src2))]>,
2476               Requires<[HasSSE2]>, XD;
2477 def DIVSDrm : I<0x5E, MRMSrcMem, (ops FR64:$dst, FR64:$src1, f64mem:$src2),
2478                 "divsd {$src2, $dst|$dst, $src2}",
2479                 [(set FR64:$dst, (fdiv FR64:$src1, (loadf64 addr:$src2)))]>,
2480               Requires<[HasSSE2]>, XD;
2481
2482 def SUBSSrr : I<0x5C, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2483                 "subss {$src2, $dst|$dst, $src2}",
2484                 [(set FR32:$dst, (fsub FR32:$src1, FR32:$src2))]>,
2485               Requires<[HasSSE1]>, XS;
2486 def SUBSSrm : I<0x5C, MRMSrcMem, (ops FR32:$dst, FR32:$src1, f32mem:$src2),
2487                 "subss {$src2, $dst|$dst, $src2}",
2488                 [(set FR32:$dst, (fsub FR32:$src1, (loadf32 addr:$src2)))]>,
2489               Requires<[HasSSE1]>, XS;
2490 def SUBSDrr : I<0x5C, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2491                 "subsd {$src2, $dst|$dst, $src2}",
2492                 [(set FR64:$dst, (fsub FR64:$src1, FR64:$src2))]>,
2493               Requires<[HasSSE2]>, XD;
2494 def SUBSDrm : I<0x5C, MRMSrcMem, (ops FR64:$dst, FR64:$src1, f64mem:$src2),
2495                 "subsd {$src2, $dst|$dst, $src2}",
2496                 [(set FR64:$dst, (fsub FR64:$src1, (loadf64 addr:$src2)))]>,
2497               Requires<[HasSSE2]>, XD;
2498
2499 // SSE Logical
2500 let isCommutable = 1 in {
2501 def ANDPSrr : I<0x54, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2502                 "andps {$src2, $dst|$dst, $src2}", []>,
2503               Requires<[HasSSE1]>, TB;
2504 def ANDPDrr : I<0x54, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2505                 "andpd {$src2, $dst|$dst, $src2}", []>,
2506               Requires<[HasSSE2]>, TB, OpSize;
2507 def ORPSrr : I<0x56, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2508                 "orps {$src2, $dst|$dst, $src2}", []>,
2509              Requires<[HasSSE1]>, TB;
2510 def ORPDrr : I<0x56, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2511                 "orpd {$src2, $dst|$dst, $src2}", []>,
2512              Requires<[HasSSE2]>, TB, OpSize;
2513 def XORPSrr : I<0x57, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2514                 "xorps {$src2, $dst|$dst, $src2}", []>,
2515               Requires<[HasSSE1]>, TB;
2516 def XORPDrr : I<0x57, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2517                 "xorpd {$src2, $dst|$dst, $src2}", []>,
2518               Requires<[HasSSE2]>, TB, OpSize;
2519 }
2520 def ANDNPSrr : I<0x55, MRMSrcReg, (ops FR32:$dst, FR32:$src1, FR32:$src2),
2521                 "andnps {$src2, $dst|$dst, $src2}", []>,
2522                Requires<[HasSSE1]>, TB;
2523 def ANDNPDrr : I<0x55, MRMSrcReg, (ops FR64:$dst, FR64:$src1, FR64:$src2),
2524                 "andnpd {$src2, $dst|$dst, $src2}", []>,
2525                Requires<[HasSSE2]>, TB, OpSize;
2526
2527 def CMPSSrr : I<0xC2, MRMSrcReg, 
2528                 (ops FR32:$dst, FR32:$src1, FR32:$src, SSECC:$cc),
2529                 "cmp${cc}ss {$src, $dst|$dst, $src}", []>,
2530               Requires<[HasSSE1]>, XS;
2531 def CMPSSrm : I<0xC2, MRMSrcMem, 
2532                 (ops FR32:$dst, FR32:$src1, f32mem:$src, SSECC:$cc),
2533                 "cmp${cc}ss {$src, $dst|$dst, $src}", []>,
2534               Requires<[HasSSE1]>, XS;
2535 def CMPSDrr : I<0xC2, MRMSrcReg, 
2536                 (ops FR64:$dst, FR64:$src1, FR64:$src, SSECC:$cc),
2537                 "cmp${cc}sd {$src, $dst|$dst, $src}", []>,
2538               Requires<[HasSSE1]>, XD;
2539 def CMPSDrm : I<0xC2, MRMSrcMem, 
2540                 (ops FR64:$dst, FR64:$src1, f64mem:$src, SSECC:$cc),
2541                 "cmp${cc}sd {$src, $dst|$dst, $src}", []>,
2542               Requires<[HasSSE2]>, XD;
2543 }
2544
2545 //===----------------------------------------------------------------------===//
2546 // Floating Point Stack Support
2547 //===----------------------------------------------------------------------===//
2548
2549 // Floating point support.  All FP Stack operations are represented with two 
2550 // instructions here.  The first instruction, generated by the instruction
2551 // selector, uses "RFP" registers: a traditional register file to reference
2552 // floating point values.  These instructions are all psuedo instructions and
2553 // use the "Fp" prefix.  The second instruction is defined with FPI, which is
2554 // the actual instruction emitted by the assembler.  The FP stackifier pass
2555 // converts one to the other after register allocation occurs.
2556 //
2557 // Note that the FpI instruction should have instruction selection info (e.g.
2558 // a pattern) and the FPI instruction should have emission info (e.g. opcode
2559 // encoding and asm printing info).
2560
2561 // FPI - Floating Point Instruction template.
2562 class FPI<bits<8> o, Format F, dag ops, string asm> : I<o, F, ops, asm, []> {}
2563
2564 // FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
2565 class FpI_<dag ops, FPFormat fp, list<dag> pattern>
2566   : X86Inst<0, Pseudo, NoImm, ops, ""> {
2567   let FPForm = fp; let FPFormBits = FPForm.Value;
2568   let Pattern = pattern;
2569 }
2570
2571 // Random Pseudo Instructions.
2572 def FpGETRESULT : FpI_<(ops RFP:$dst), SpecialFP,
2573                   [(set RFP:$dst, X86fpget)]>;                    // FPR = ST(0)
2574
2575 let noResults = 1 in 
2576   def FpSETRESULT : FpI_<(ops RFP:$src), SpecialFP,
2577                         [(X86fpset RFP:$src)]>, Imp<[], [ST0]>;   // ST(0) = FPR
2578
2579 // FpI - Floating Point Psuedo Instruction template. Predicated on FPStack.
2580 class FpI<dag ops, FPFormat fp, list<dag> pattern> :
2581   FpI_<ops, fp, pattern>, Requires<[FPStack]>;
2582
2583
2584 def FpMOV       : FpI<(ops RFP:$dst, RFP:$src), SpecialFP, []>; // f1 = fmov f2
2585
2586 // Arithmetic
2587 // Add, Sub, Mul, Div.
2588 def FpADD : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
2589                 [(set RFP:$dst, (fadd RFP:$src1, RFP:$src2))]>;
2590 def FpSUB : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
2591                 [(set RFP:$dst, (fsub RFP:$src1, RFP:$src2))]>;
2592 def FpMUL : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
2593                 [(set RFP:$dst, (fmul RFP:$src1, RFP:$src2))]>;
2594 def FpDIV : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
2595                 [(set RFP:$dst, (fdiv RFP:$src1, RFP:$src2))]>;
2596
2597 class FPST0rInst<bits<8> o, string asm>
2598   : FPI<o, AddRegFrm, (ops RST:$op), asm>, D8;
2599 class FPrST0Inst<bits<8> o, string asm>
2600   : FPI<o, AddRegFrm, (ops RST:$op), asm>, DC;
2601 class FPrST0PInst<bits<8> o, string asm>
2602   : FPI<o, AddRegFrm, (ops RST:$op), asm>, DE;
2603
2604 // Binary Ops with a memory source.
2605 def FpADD32m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2606                     [(set RFP:$dst, (fadd RFP:$src1,
2607                                      (extloadf64f32 addr:$src2)))]>;
2608                 // ST(0) = ST(0) + [mem32]
2609 def FpADD64m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2610                     [(set RFP:$dst, (fadd RFP:$src1, (loadf64 addr:$src2)))]>;
2611                 // ST(0) = ST(0) + [mem64]
2612 def FpMUL32m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2613                     [(set RFP:$dst, (fmul RFP:$src1,
2614                                      (extloadf64f32 addr:$src2)))]>;
2615                 // ST(0) = ST(0) * [mem32]
2616 def FpMUL64m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2617                     [(set RFP:$dst, (fmul RFP:$src1, (loadf64 addr:$src2)))]>;
2618                 // ST(0) = ST(0) * [mem64]
2619 def FpSUB32m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2620                     [(set RFP:$dst, (fsub RFP:$src1,
2621                                     (extloadf64f32 addr:$src2)))]>;
2622                 // ST(0) = ST(0) - [mem32]
2623 def FpSUB64m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2624                     [(set RFP:$dst, (fsub RFP:$src1, (loadf64 addr:$src2)))]>;
2625                 // ST(0) = ST(0) - [mem64]
2626 def FpSUBR32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2627                     [(set RFP:$dst, (fsub (extloadf64f32 addr:$src2),
2628                                      RFP:$src1))]>;
2629                 // ST(0) = [mem32] - ST(0)
2630 def FpSUBR64m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2631                     [(set RFP:$dst, (fsub (loadf64 addr:$src2), RFP:$src1))]>;
2632                 // ST(0) = [mem64] - ST(0)
2633 def FpDIV32m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2634                     [(set RFP:$dst, (fdiv RFP:$src1,
2635                                     (extloadf64f32 addr:$src2)))]>;
2636                 // ST(0) = ST(0) / [mem32]
2637 def FpDIV64m  : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2638                     [(set RFP:$dst, (fdiv RFP:$src1, (loadf64 addr:$src2)))]>;
2639                 // ST(0) = ST(0) / [mem64]
2640 def FpDIVR32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2641                     [(set RFP:$dst, (fdiv (extloadf64f32 addr:$src2),
2642                                      RFP:$src1))]>;
2643                 // ST(0) = [mem32] / ST(0)
2644 def FpDIVR64m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
2645                     [(set RFP:$dst, (fdiv (loadf64 addr:$src2), RFP:$src1))]>;
2646                 // ST(0) = [mem64] / ST(0)
2647
2648
2649 def FADD32m  : FPI<0xD8, MRM0m, (ops f32mem:$src), "fadd{s} $src">;
2650 def FADD64m  : FPI<0xDC, MRM0m, (ops f64mem:$src), "fadd{l} $src">;
2651 def FMUL32m  : FPI<0xD8, MRM1m, (ops f32mem:$src), "fmul{s} $src">;
2652 def FMUL64m  : FPI<0xDC, MRM1m, (ops f64mem:$src), "fmul{l} $src">;
2653 def FSUB32m  : FPI<0xD8, MRM4m, (ops f32mem:$src), "fsub{s} $src">;
2654 def FSUB64m  : FPI<0xDC, MRM4m, (ops f64mem:$src), "fsub{l} $src">;
2655 def FSUBR32m : FPI<0xD8, MRM5m, (ops f32mem:$src), "fsubr{s} $src">;
2656 def FSUBR64m : FPI<0xDC, MRM5m, (ops f64mem:$src), "fsubr{l} $src">;
2657 def FDIV32m  : FPI<0xD8, MRM6m, (ops f32mem:$src), "fdiv{s} $src">;
2658 def FDIV64m  : FPI<0xDC, MRM6m, (ops f64mem:$src), "fdiv{l} $src">;
2659 def FDIVR32m : FPI<0xD8, MRM7m, (ops f32mem:$src), "fdivr{s} $src">;
2660 def FDIVR64m : FPI<0xDC, MRM7m, (ops f64mem:$src), "fdivr{l} $src">;
2661
2662 // FIXME: Implement these when we have a dag-dag isel!
2663 def FpIADD16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2664                     [(set RFP:$dst, (fadd RFP:$src1,
2665                                      (sint_to_fp (loadi16 addr:$src2))))]>;
2666                 // ST(0) = ST(0) + [mem16int]
2667 def FpIADD32m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2668                     [(set RFP:$dst, (fadd RFP:$src1,
2669                                      (sint_to_fp (loadi32 addr:$src2))))]>;
2670                 // ST(0) = ST(0) + [mem32int]
2671 def FpIMUL16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2672                     [(set RFP:$dst, (fmul RFP:$src1,
2673                                      (sint_to_fp (loadi16 addr:$src2))))]>;
2674                 // ST(0) = ST(0) * [mem16int]
2675 def FpIMUL32m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2676                     [(set RFP:$dst, (fmul RFP:$src1,
2677                                      (sint_to_fp (loadi32 addr:$src2))))]>;
2678                 // ST(0) = ST(0) * [mem32int]
2679 def FpISUB16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2680                     [(set RFP:$dst, (fsub RFP:$src1,
2681                                      (sint_to_fp (loadi16 addr:$src2))))]>;
2682                 // ST(0) = ST(0) - [mem16int]
2683 def FpISUB32m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2684                     [(set RFP:$dst, (fsub RFP:$src1,
2685                                      (sint_to_fp (loadi32 addr:$src2))))]>;
2686                 // ST(0) = ST(0) - [mem32int]
2687 def FpISUBR16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2688                      [(set RFP:$dst, (fsub (sint_to_fp (loadi16 addr:$src2)),
2689                                       RFP:$src1))]>;
2690                 // ST(0) = [mem16int] - ST(0)
2691 def FpISUBR32m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2692                      [(set RFP:$dst, (fsub (sint_to_fp (loadi32 addr:$src2)),
2693                                       RFP:$src1))]>;
2694                 // ST(0) = [mem32int] - ST(0)
2695 def FpIDIV16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2696                     [(set RFP:$dst, (fdiv RFP:$src1,
2697                                      (sint_to_fp (loadi16 addr:$src2))))]>;
2698                 // ST(0) = ST(0) / [mem16int]
2699 def FpIDIV32m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2700                     [(set RFP:$dst, (fdiv RFP:$src1,
2701                                      (sint_to_fp (loadi32 addr:$src2))))]>;
2702                 // ST(0) = ST(0) / [mem32int]
2703 def FpIDIVR16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2704                      [(set RFP:$dst, (fdiv (sint_to_fp (loadi16 addr:$src2)),
2705                                       RFP:$src1))]>;
2706                 // ST(0) = [mem16int] / ST(0)
2707 def FpIDIVR32m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
2708                      [(set RFP:$dst, (fdiv (sint_to_fp (loadi32 addr:$src2)),
2709                                       RFP:$src1))]>;
2710                 // ST(0) = [mem32int] / ST(0)
2711
2712 def FIADD16m  : FPI<0xDE, MRM0m, (ops i16mem:$src), "fiadd{s} $src">;
2713 def FIADD32m  : FPI<0xDA, MRM0m, (ops i32mem:$src), "fiadd{l} $src">;
2714 def FIMUL16m  : FPI<0xDE, MRM1m, (ops i16mem:$src), "fimul{s} $src">;
2715 def FIMUL32m  : FPI<0xDA, MRM1m, (ops i32mem:$src), "fimul{l} $src">;
2716 def FISUB16m  : FPI<0xDE, MRM4m, (ops i16mem:$src), "fisub{s} $src">;
2717 def FISUB32m  : FPI<0xDA, MRM4m, (ops i32mem:$src), "fisub{l} $src">;
2718 def FISUBR16m : FPI<0xDE, MRM5m, (ops i16mem:$src), "fisubr{s} $src">;
2719 def FISUBR32m : FPI<0xDA, MRM5m, (ops i32mem:$src), "fisubr{l} $src">;
2720 def FIDIV16m  : FPI<0xDE, MRM6m, (ops i16mem:$src), "fidiv{s} $src">;
2721 def FIDIV32m  : FPI<0xDA, MRM6m, (ops i32mem:$src), "fidiv{s} $src">;
2722 def FIDIVR16m : FPI<0xDE, MRM7m, (ops i16mem:$src), "fidivr{s} $src">;
2723 def FIDIVR32m : FPI<0xDA, MRM7m, (ops i32mem:$src), "fidivr{s} $src">;
2724
2725 // NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
2726 // of some of the 'reverse' forms of the fsub and fdiv instructions.  As such,
2727 // we have to put some 'r's in and take them out of weird places.
2728 def FADDST0r   : FPST0rInst <0xC0, "fadd $op">;
2729 def FADDrST0   : FPrST0Inst <0xC0, "fadd {%ST(0), $op|$op, %ST(0)}">;
2730 def FADDPrST0  : FPrST0PInst<0xC0, "faddp $op">;
2731 def FSUBRST0r  : FPST0rInst <0xE8, "fsubr $op">;
2732 def FSUBrST0   : FPrST0Inst <0xE8, "fsub{r} {%ST(0), $op|$op, %ST(0)}">;
2733 def FSUBPrST0  : FPrST0PInst<0xE8, "fsub{r}p $op">;
2734 def FSUBST0r   : FPST0rInst <0xE0, "fsub $op">;
2735 def FSUBRrST0  : FPrST0Inst <0xE0, "fsub{|r} {%ST(0), $op|$op, %ST(0)}">;
2736 def FSUBRPrST0 : FPrST0PInst<0xE0, "fsub{|r}p $op">;
2737 def FMULST0r   : FPST0rInst <0xC8, "fmul $op">;
2738 def FMULrST0   : FPrST0Inst <0xC8, "fmul {%ST(0), $op|$op, %ST(0)}">;
2739 def FMULPrST0  : FPrST0PInst<0xC8, "fmulp $op">;
2740 def FDIVRST0r  : FPST0rInst <0xF8, "fdivr $op">;
2741 def FDIVrST0   : FPrST0Inst <0xF8, "fdiv{r} {%ST(0), $op|$op, %ST(0)}">;
2742 def FDIVPrST0  : FPrST0PInst<0xF8, "fdiv{r}p $op">;
2743 def FDIVST0r   : FPST0rInst <0xF0, "fdiv $op">;
2744 def FDIVRrST0  : FPrST0Inst <0xF0, "fdiv{|r} {%ST(0), $op|$op, %ST(0)}">;
2745 def FDIVRPrST0 : FPrST0PInst<0xF0, "fdiv{|r}p $op">;
2746
2747
2748 // Unary operations.
2749 def FpCHS  : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2750                  [(set RFP:$dst, (fneg RFP:$src))]>;
2751 def FpABS  : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2752                  [(set RFP:$dst, (fabs RFP:$src))]>;
2753 def FpSQRT : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2754                  [(set RFP:$dst, (fsqrt RFP:$src))]>;
2755 def FpSIN  : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2756                  [(set RFP:$dst, (fsin RFP:$src))]>;
2757 def FpCOS  : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
2758                  [(set RFP:$dst, (fcos RFP:$src))]>;
2759 def FpTST  : FpI<(ops RFP:$src), OneArgFP,
2760                  []>;
2761
2762 def FCHS  : FPI<0xE0, RawFrm, (ops), "fchs">, D9;
2763 def FABS  : FPI<0xE1, RawFrm, (ops), "fabs">, D9;
2764 def FSQRT : FPI<0xFA, RawFrm, (ops), "fsqrt">, D9;
2765 def FSIN  : FPI<0xFE, RawFrm, (ops), "fsin">, D9;
2766 def FCOS  : FPI<0xFF, RawFrm, (ops), "fcos">, D9;
2767 def FTST  : FPI<0xE4, RawFrm, (ops), "ftst">, D9;
2768
2769
2770 // Floating point cmovs.
2771 let isTwoAddress = 1 in {
2772   def FpCMOVB  : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2773                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2774                                       X86_COND_B, STATUS))]>;
2775   def FpCMOVBE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2776                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2777                                       X86_COND_BE, STATUS))]>;
2778   def FpCMOVE  : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2779                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2780                                       X86_COND_E, STATUS))]>;
2781   def FpCMOVP  : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2782                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2783                                       X86_COND_P, STATUS))]>;
2784   def FpCMOVAE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2785                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2786                                       X86_COND_AE, STATUS))]>;
2787   def FpCMOVA  : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2788                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2789                                       X86_COND_A, STATUS))]>;
2790   def FpCMOVNE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2791                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2792                                       X86_COND_NE, STATUS))]>;
2793   def FpCMOVNP : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
2794                      [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
2795                                       X86_COND_NP, STATUS))]>;
2796 }
2797
2798 def FCMOVB  : FPI<0xC0, AddRegFrm, (ops RST:$op),
2799                   "fcmovb {$op, %ST(0)|%ST(0), $op}">, DA;
2800 def FCMOVBE : FPI<0xD0, AddRegFrm, (ops RST:$op),
2801                   "fcmovbe {$op, %ST(0)|%ST(0), $op}">, DA;
2802 def FCMOVE  : FPI<0xC8, AddRegFrm, (ops RST:$op),
2803                   "fcmove {$op, %ST(0)|%ST(0), $op}">, DA;
2804 def FCMOVP  : FPI<0xD8, AddRegFrm, (ops RST:$op),
2805                   "fcmovu  {$op, %ST(0)|%ST(0), $op}">, DA;
2806 def FCMOVAE : FPI<0xC0, AddRegFrm, (ops RST:$op),
2807                   "fcmovae {$op, %ST(0)|%ST(0), $op}">, DB;
2808 def FCMOVA  : FPI<0xD0, AddRegFrm, (ops RST:$op),
2809                   "fcmova {$op, %ST(0)|%ST(0), $op}">, DB;
2810 def FCMOVNE : FPI<0xC8, AddRegFrm, (ops RST:$op),
2811                   "fcmovne {$op, %ST(0)|%ST(0), $op}">, DB;
2812 def FCMOVNP : FPI<0xD8, AddRegFrm, (ops RST:$op),
2813                   "fcmovnu {$op, %ST(0)|%ST(0), $op}">, DB;
2814
2815 // Floating point loads & stores.
2816 def FpLD32m  : FpI<(ops RFP:$dst, f32mem:$src), ZeroArgFP,
2817                    [(set RFP:$dst, (extloadf64f32 addr:$src))]>;
2818 def FpLD64m  : FpI<(ops RFP:$dst, f64mem:$src), ZeroArgFP,
2819                    [(set RFP:$dst, (loadf64 addr:$src))]>;
2820 def FpILD16m : FpI<(ops RFP:$dst, i16mem:$src), ZeroArgFP,
2821                    [(set RFP:$dst, (sint_to_fp (loadi16 addr:$src)))]>;
2822 def FpILD32m : FpI<(ops RFP:$dst, i32mem:$src), ZeroArgFP,
2823                    [(set RFP:$dst, (sint_to_fp (loadi32 addr:$src)))]>;
2824 def FpILD64m : FpI<(ops RFP:$dst, i64mem:$src), ZeroArgFP,
2825                    [(set RFP:$dst, (X86fild64m addr:$src))]>;
2826
2827 def FpST32m   : FpI<(ops f32mem:$op, RFP:$src), OneArgFP,
2828                 [(truncstore RFP:$src, addr:$op, f32)]>;
2829 def FpST64m   : FpI<(ops f64mem:$op, RFP:$src), OneArgFP,
2830                 [(store RFP:$src, addr:$op)]>;
2831
2832 def FpSTP32m  : FpI<(ops f32mem:$op, RFP:$src), OneArgFP, []>;
2833 def FpSTP64m  : FpI<(ops f64mem:$op, RFP:$src), OneArgFP, []>;
2834 def FpIST16m  : FpI<(ops i16mem:$op, RFP:$src), OneArgFP, []>;
2835 def FpIST32m  : FpI<(ops i32mem:$op, RFP:$src), OneArgFP, []>;
2836 def FpIST64m  : FpI<(ops i64mem:$op, RFP:$src), OneArgFP, []>;
2837
2838 def FLD32m   : FPI<0xD9, MRM0m, (ops f32mem:$src), "fld{s} $src">;
2839 def FLD64m   : FPI<0xDD, MRM0m, (ops f64mem:$src), "fld{l} $src">;
2840 def FILD16m  : FPI<0xDF, MRM0m, (ops i16mem:$src), "fild{s} $src">;
2841 def FILD32m  : FPI<0xDB, MRM0m, (ops i32mem:$src), "fild{l} $src">;
2842 def FILD64m  : FPI<0xDF, MRM5m, (ops i64mem:$src), "fild{ll} $src">;
2843 def FST32m   : FPI<0xD9, MRM2m, (ops f32mem:$dst), "fst{s} $dst">;
2844 def FST64m   : FPI<0xDD, MRM2m, (ops f64mem:$dst), "fst{l} $dst">;
2845 def FSTP32m  : FPI<0xD9, MRM3m, (ops f32mem:$dst), "fstp{s} $dst">;
2846 def FSTP64m  : FPI<0xDD, MRM3m, (ops f64mem:$dst), "fstp{l} $dst">;
2847 def FIST16m  : FPI<0xDF, MRM2m, (ops i16mem:$dst), "fist{s} $dst">;
2848 def FIST32m  : FPI<0xDB, MRM2m, (ops i32mem:$dst), "fist{l} $dst">;
2849 def FISTP16m : FPI<0xDF, MRM3m, (ops i16mem:$dst), "fistp{s} $dst">;
2850 def FISTP32m : FPI<0xDB, MRM3m, (ops i32mem:$dst), "fistp{l} $dst">;
2851 def FISTP64m : FPI<0xDF, MRM7m, (ops i64mem:$dst), "fistp{ll} $dst">;
2852
2853 // FP Stack manipulation instructions.
2854 def FLDrr   : FPI<0xC0, AddRegFrm, (ops RST:$op), "fld $op">, D9;
2855 def FSTrr   : FPI<0xD0, AddRegFrm, (ops RST:$op), "fst $op">, DD;
2856 def FSTPrr  : FPI<0xD8, AddRegFrm, (ops RST:$op), "fstp $op">, DD;
2857 def FXCH    : FPI<0xC8, AddRegFrm, (ops RST:$op), "fxch $op">, D9;
2858
2859 // Floating point constant loads.
2860 def FpLD0 : FpI<(ops RFP:$dst), ZeroArgFP,
2861                 [(set RFP:$dst, fp64imm0)]>;
2862 def FpLD1 : FpI<(ops RFP:$dst), ZeroArgFP,
2863                 [(set RFP:$dst, fp64imm1)]>;
2864
2865 def FLD0 : FPI<0xEE, RawFrm, (ops), "fldz">, D9;
2866 def FLD1 : FPI<0xE8, RawFrm, (ops), "fld1">, D9;
2867
2868
2869 // Floating point compares.
2870 def FpUCOMr   : FpI<(ops RFP:$lhs, RFP:$rhs), CompareFP,
2871                     []>;  // FPSW = cmp ST(0) with ST(i)
2872 def FpUCOMIr  : FpI<(ops RFP:$lhs, RFP:$rhs), CompareFP,
2873                     [(set STATUS, (X86cmp RFP:$lhs, RFP:$rhs))]>,
2874                 Imp<[],[STATUS]>;       // CC = cmp ST(0) with ST(i)
2875
2876 def FUCOMr    : FPI<0xE0, AddRegFrm,    // FPSW = cmp ST(0) with ST(i)
2877                     (ops RST:$reg),
2878                     "fucom $reg">, DD, Imp<[ST0],[]>;
2879 def FUCOMPr   : FPI<0xE8, AddRegFrm,    // FPSW = cmp ST(0) with ST(i), pop
2880                   (ops RST:$reg),
2881                   "fucomp $reg">, DD, Imp<[ST0],[]>;
2882 def FUCOMPPr  : FPI<0xE9, RawFrm,       // cmp ST(0) with ST(1), pop, pop
2883                   (ops),
2884                   "fucompp">, DA, Imp<[ST0],[]>;
2885
2886 def FUCOMIr  : FPI<0xE8, AddRegFrm,     // CC = cmp ST(0) with ST(i)
2887                    (ops RST:$reg),
2888                    "fucomi {$reg, %ST(0)|%ST(0), $reg}">, DB, Imp<[ST0],[]>;
2889 def FUCOMIPr : FPI<0xE8, AddRegFrm,     // CC = cmp ST(0) with ST(i), pop
2890                  (ops RST:$reg),
2891                  "fucomip {$reg, %ST(0)|%ST(0), $reg}">, DF, Imp<[ST0],[]>;
2892
2893
2894 // Floating point flag ops.
2895 def FNSTSW8r  : I<0xE0, RawFrm,                  // AX = fp flags
2896                   (ops), "fnstsw", []>, DF, Imp<[],[AX]>;
2897
2898 def FNSTCW16m : I<0xD9, MRM7m,                   // [mem16] = X87 control world
2899                   (ops i16mem:$dst), "fnstcw $dst", []>;
2900 def FLDCW16m  : I<0xD9, MRM5m,                   // X87 control world = [mem16]
2901                   (ops i16mem:$dst), "fldcw $dst", []>;
2902
2903
2904 //===----------------------------------------------------------------------===//
2905 // Miscellaneous Instructions
2906 //===----------------------------------------------------------------------===//
2907
2908 def RDTSC : I<0x31, RawFrm, (ops), "rdtsc", [(X86rdtsc)]>,
2909             TB, Imp<[],[EAX,EDX]>;
2910
2911
2912 //===----------------------------------------------------------------------===//
2913 // Non-Instruction Patterns
2914 //===----------------------------------------------------------------------===//
2915
2916 // Calls
2917 def : Pat<(X86call tglobaladdr:$dst),
2918           (CALLpcrel32 tglobaladdr:$dst)>;
2919 def : Pat<(X86call texternalsym:$dst),
2920           (CALLpcrel32 texternalsym:$dst)>;
2921
2922 // X86 specific add which produces a flag.
2923 def : Pat<(X86addflag R32:$src1, R32:$src2),
2924           (ADD32rr R32:$src1, R32:$src2)>;
2925 def : Pat<(X86addflag R32:$src1, (load addr:$src2)),
2926           (ADD32rm R32:$src1, addr:$src2)>;
2927 def : Pat<(X86addflag R32:$src1, imm:$src2),
2928           (ADD32ri R32:$src1, imm:$src2)>;
2929 def : Pat<(X86addflag R32:$src1, i32immSExt8:$src2),
2930           (ADD32ri8 R32:$src1, i32immSExt8:$src2)>;
2931
2932 def : Pat<(X86subflag R32:$src1, R32:$src2),
2933           (SUB32rr R32:$src1, R32:$src2)>;
2934 def : Pat<(X86subflag R32:$src1, (load addr:$src2)),
2935           (SUB32rm R32:$src1, addr:$src2)>;
2936 def : Pat<(X86subflag R32:$src1, imm:$src2),
2937           (SUB32ri R32:$src1, imm:$src2)>;
2938 def : Pat<(X86subflag R32:$src1, i32immSExt8:$src2),
2939           (SUB32ri8 R32:$src1, i32immSExt8:$src2)>;
2940
2941 // {s|z}extload bool -> {s|z}extload byte
2942 def : Pat<(sextloadi16i1 addr:$src), (MOVSX16rm8 addr:$src)>;
2943 def : Pat<(sextloadi32i1 addr:$src), (MOVSX32rm8 addr:$src)>;
2944 def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
2945 def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
2946
2947 // extload bool -> extload byte
2948 def : Pat<(extloadi8i1 addr:$src), (MOV8rm addr:$src)>;
2949
2950 // anyext -> zext
2951 def : Pat<(i16 (anyext R8 :$src)), (MOVZX16rr8  R8 :$src)>;
2952 def : Pat<(i32 (anyext R8 :$src)), (MOVZX32rr8  R8 :$src)>;
2953 def : Pat<(i32 (anyext R16:$src)), (MOVZX32rr16 R16:$src)>;
2954
2955 // Required for RET of f32 / f64 values.
2956 def : Pat<(X86fld addr:$src, f32), (FpLD32m addr:$src)>;
2957 def : Pat<(X86fld addr:$src, f64), (FpLD64m addr:$src)>;
2958
2959 // Required for CALL which return f32 / f64 values.
2960 def : Pat<(X86fst RFP:$src, addr:$op, f32), (FpST32m addr:$op, RFP:$src)>;
2961 def : Pat<(X86fst RFP:$src, addr:$op, f64), (FpST64m addr:$op, RFP:$src)>;
2962
2963 // Floatin point constant -0.0 and -1.0
2964 def : Pat<(f64 fp64immneg0), (FpCHS (FpLD0))>, Requires<[FPStack]>;
2965 def : Pat<(f64 fp64immneg1), (FpCHS (FpLD1))>, Requires<[FPStack]>;
2966
2967 // RFP undef
2968 def : Pat<(f64 (undef)), (FpLD0)>,  Requires<[FPStack]>;
2969
2970
2971 //===----------------------------------------------------------------------===//
2972 // Some peepholes
2973 //===----------------------------------------------------------------------===//
2974
2975 // (shl x, 1) ==> (add x, x)
2976 def : Pat<(shl R8 :$src1, (i8 1)), (ADD8rr  R8 :$src1, R8 :$src1)>;
2977 def : Pat<(shl R16:$src1, (i8 1)), (ADD16rr R16:$src1, R16:$src1)>;
2978 def : Pat<(shl R32:$src1, (i8 1)), (ADD32rr R32:$src1, R32:$src1)>;