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