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