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