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