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