move VMX instructions out to their own file.
[oota-llvm.git] / lib / Target / X86 / X86InstrInfo.td
1 //===- X86InstrInfo.td - Main X86 Instruction Definition ---*- 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<1, 2, [SDTCisVT<0, i32>, SDTCisSameAs<1, 2>]>;
25
26 def SDTX86Cmov    : SDTypeProfile<1, 4,
27                                   [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
28                                    SDTCisVT<3, i8>, SDTCisVT<4, i32>]>;
29
30 // Unary and binary operator instructions that set EFLAGS as a side-effect.
31 def SDTUnaryArithWithFlags : SDTypeProfile<2, 1,
32                                            [SDTCisInt<0>, SDTCisVT<1, i32>]>;
33
34 def SDTBinaryArithWithFlags : SDTypeProfile<2, 2,
35                                             [SDTCisSameAs<0, 2>,
36                                              SDTCisSameAs<0, 3>,
37                                              SDTCisInt<0>, SDTCisVT<1, i32>]>;
38 def SDTX86BrCond  : SDTypeProfile<0, 3,
39                                   [SDTCisVT<0, OtherVT>,
40                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
41
42 def SDTX86SetCC   : SDTypeProfile<1, 2,
43                                   [SDTCisVT<0, i8>,
44                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
45 def SDTX86SetCC_C : SDTypeProfile<1, 2,
46                                   [SDTCisInt<0>,
47                                    SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
48
49 def SDTX86cas : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisInt<1>, 
50                                      SDTCisVT<2, i8>]>;
51 def SDTX86cas8 : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
52
53 def SDTX86atomicBinary : SDTypeProfile<2, 3, [SDTCisInt<0>, SDTCisInt<1>,
54                                 SDTCisPtrTy<2>, SDTCisInt<3>,SDTCisInt<4>]>;
55 def SDTX86Ret     : SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>;
56
57 def SDT_X86CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
58 def SDT_X86CallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>,
59                                         SDTCisVT<1, i32>]>;
60
61 def SDT_X86Call   : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
62
63 def SDT_X86VASTART_SAVE_XMM_REGS : SDTypeProfile<0, -1, [SDTCisVT<0, i8>,
64                                                          SDTCisVT<1, iPTR>,
65                                                          SDTCisVT<2, iPTR>]>;
66
67 def SDTX86RepStr  : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>;
68
69 def SDTX86Void    : SDTypeProfile<0, 0, []>;
70
71 def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
72
73 def SDT_X86TLSADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
74
75 def SDT_X86TLSCALL : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
76
77 def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
78
79 def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
80
81 def SDT_X86MEMBARRIER : SDTypeProfile<0, 0, []>;
82 def SDT_X86MEMBARRIERNoSSE : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
83
84 def X86MemBarrier : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIER,
85                             [SDNPHasChain]>;
86 def X86MemBarrierNoSSE : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIERNoSSE,
87                                 [SDNPHasChain]>;
88 def X86MFence : SDNode<"X86ISD::MFENCE", SDT_X86MEMBARRIER,
89                         [SDNPHasChain]>;
90 def X86SFence : SDNode<"X86ISD::SFENCE", SDT_X86MEMBARRIER,
91                         [SDNPHasChain]>;
92 def X86LFence : SDNode<"X86ISD::LFENCE", SDT_X86MEMBARRIER,
93                         [SDNPHasChain]>;
94
95
96 def X86bsf     : SDNode<"X86ISD::BSF",      SDTUnaryArithWithFlags>;
97 def X86bsr     : SDNode<"X86ISD::BSR",      SDTUnaryArithWithFlags>;
98 def X86shld    : SDNode<"X86ISD::SHLD",     SDTIntShiftDOp>;
99 def X86shrd    : SDNode<"X86ISD::SHRD",     SDTIntShiftDOp>;
100
101 def X86cmp     : SDNode<"X86ISD::CMP" ,     SDTX86CmpTest>;
102 def X86bt      : SDNode<"X86ISD::BT",       SDTX86CmpTest>;
103
104 def X86cmov    : SDNode<"X86ISD::CMOV",     SDTX86Cmov>;
105 def X86brcond  : SDNode<"X86ISD::BRCOND",   SDTX86BrCond,
106                         [SDNPHasChain]>;
107 def X86setcc   : SDNode<"X86ISD::SETCC",    SDTX86SetCC>;
108 def X86setcc_c : SDNode<"X86ISD::SETCC_CARRY", SDTX86SetCC_C>;
109
110 def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas,
111                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
112                          SDNPMayLoad, SDNPMemOperand]>;
113 def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86cas8,
114                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
115                          SDNPMayLoad, SDNPMemOperand]>;
116 def X86AtomAdd64 : SDNode<"X86ISD::ATOMADD64_DAG", SDTX86atomicBinary,
117                         [SDNPHasChain, SDNPMayStore, 
118                          SDNPMayLoad, SDNPMemOperand]>;
119 def X86AtomSub64 : SDNode<"X86ISD::ATOMSUB64_DAG", SDTX86atomicBinary,
120                         [SDNPHasChain, SDNPMayStore, 
121                          SDNPMayLoad, SDNPMemOperand]>;
122 def X86AtomOr64 : SDNode<"X86ISD::ATOMOR64_DAG", SDTX86atomicBinary,
123                         [SDNPHasChain, SDNPMayStore, 
124                          SDNPMayLoad, SDNPMemOperand]>;
125 def X86AtomXor64 : SDNode<"X86ISD::ATOMXOR64_DAG", SDTX86atomicBinary,
126                         [SDNPHasChain, SDNPMayStore, 
127                          SDNPMayLoad, SDNPMemOperand]>;
128 def X86AtomAnd64 : SDNode<"X86ISD::ATOMAND64_DAG", SDTX86atomicBinary,
129                         [SDNPHasChain, SDNPMayStore, 
130                          SDNPMayLoad, SDNPMemOperand]>;
131 def X86AtomNand64 : SDNode<"X86ISD::ATOMNAND64_DAG", SDTX86atomicBinary,
132                         [SDNPHasChain, SDNPMayStore, 
133                          SDNPMayLoad, SDNPMemOperand]>;
134 def X86AtomSwap64 : SDNode<"X86ISD::ATOMSWAP64_DAG", SDTX86atomicBinary,
135                         [SDNPHasChain, SDNPMayStore, 
136                          SDNPMayLoad, SDNPMemOperand]>;
137 def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
138                         [SDNPHasChain, SDNPOptInFlag, SDNPVariadic]>;
139
140 def X86vastart_save_xmm_regs :
141                  SDNode<"X86ISD::VASTART_SAVE_XMM_REGS",
142                         SDT_X86VASTART_SAVE_XMM_REGS,
143                         [SDNPHasChain, SDNPVariadic]>;
144
145 def X86callseq_start :
146                  SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
147                         [SDNPHasChain, SDNPOutFlag]>;
148 def X86callseq_end :
149                  SDNode<"ISD::CALLSEQ_END",   SDT_X86CallSeqEnd,
150                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;       
151
152 def X86call    : SDNode<"X86ISD::CALL",     SDT_X86Call,
153                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag,
154                          SDNPVariadic]>;
155
156 def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
157                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore]>;
158 def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
159                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
160                          SDNPMayLoad]>;
161
162 def X86rdtsc   : SDNode<"X86ISD::RDTSC_DAG", SDTX86Void,
163                         [SDNPHasChain, SDNPOutFlag, SDNPSideEffect]>;
164
165 def X86Wrapper    : SDNode<"X86ISD::Wrapper",     SDTX86Wrapper>;
166 def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP",  SDTX86Wrapper>;
167
168 def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR,
169                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
170
171 def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET,
172                         [SDNPHasChain]>;
173
174 def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET, 
175                         [SDNPHasChain,  SDNPOptInFlag, SDNPVariadic]>;
176
177 def X86add_flag  : SDNode<"X86ISD::ADD",  SDTBinaryArithWithFlags,
178                           [SDNPCommutative]>;
179 def X86sub_flag  : SDNode<"X86ISD::SUB",  SDTBinaryArithWithFlags>;
180 def X86smul_flag : SDNode<"X86ISD::SMUL", SDTBinaryArithWithFlags,
181                           [SDNPCommutative]>;
182 def X86umul_flag : SDNode<"X86ISD::UMUL", SDTUnaryArithWithFlags,
183                           [SDNPCommutative]>;
184                           
185 def X86inc_flag  : SDNode<"X86ISD::INC",  SDTUnaryArithWithFlags>;
186 def X86dec_flag  : SDNode<"X86ISD::DEC",  SDTUnaryArithWithFlags>;
187 def X86or_flag   : SDNode<"X86ISD::OR",   SDTBinaryArithWithFlags,
188                           [SDNPCommutative]>;
189 def X86xor_flag  : SDNode<"X86ISD::XOR",  SDTBinaryArithWithFlags,
190                           [SDNPCommutative]>;
191 def X86and_flag  : SDNode<"X86ISD::AND",  SDTBinaryArithWithFlags,
192                           [SDNPCommutative]>;
193
194 def X86mul_imm : SDNode<"X86ISD::MUL_IMM", SDTIntBinOp>;
195
196 def X86MingwAlloca : SDNode<"X86ISD::MINGW_ALLOCA", SDTX86Void,
197                             [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
198                             
199 def X86TLSCall : SDNode<"X86ISD::TLSCALL", SDT_X86TLSCALL,
200                         []>;
201
202 //===----------------------------------------------------------------------===//
203 // X86 Operand Definitions.
204 //
205
206 // A version of ptr_rc which excludes SP, ESP, and RSP. This is used for
207 // the index operand of an address, to conform to x86 encoding restrictions.
208 def ptr_rc_nosp : PointerLikeRegClass<1>;
209
210 // *mem - Operand definitions for the funky X86 addressing mode operands.
211 //
212 def X86MemAsmOperand : AsmOperandClass {
213   let Name = "Mem";
214   let SuperClasses = [];
215 }
216 def X86AbsMemAsmOperand : AsmOperandClass {
217   let Name = "AbsMem";
218   let SuperClasses = [X86MemAsmOperand];
219 }
220 class X86MemOperand<string printMethod> : Operand<iPTR> {
221   let PrintMethod = printMethod;
222   let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
223   let ParserMatchClass = X86MemAsmOperand;
224 }
225
226 def opaque32mem : X86MemOperand<"printopaquemem">;
227 def opaque48mem : X86MemOperand<"printopaquemem">;
228 def opaque80mem : X86MemOperand<"printopaquemem">;
229 def opaque512mem : X86MemOperand<"printopaquemem">;
230
231 def i8mem   : X86MemOperand<"printi8mem">;
232 def i16mem  : X86MemOperand<"printi16mem">;
233 def i32mem  : X86MemOperand<"printi32mem">;
234 def i64mem  : X86MemOperand<"printi64mem">;
235 def i128mem : X86MemOperand<"printi128mem">;
236 def i256mem : X86MemOperand<"printi256mem">;
237 def f32mem  : X86MemOperand<"printf32mem">;
238 def f64mem  : X86MemOperand<"printf64mem">;
239 def f80mem  : X86MemOperand<"printf80mem">;
240 def f128mem : X86MemOperand<"printf128mem">;
241 def f256mem : X86MemOperand<"printf256mem">;
242
243 // A version of i8mem for use on x86-64 that uses GR64_NOREX instead of
244 // plain GR64, so that it doesn't potentially require a REX prefix.
245 def i8mem_NOREX : Operand<i64> {
246   let PrintMethod = "printi8mem";
247   let MIOperandInfo = (ops GR64_NOREX, i8imm, GR64_NOREX_NOSP, i32imm, i8imm);
248   let ParserMatchClass = X86MemAsmOperand;
249 }
250
251 // Special i32mem for addresses of load folding tail calls. These are not
252 // allowed to use callee-saved registers since they must be scheduled
253 // after callee-saved register are popped.
254 def i32mem_TC : Operand<i32> {
255   let PrintMethod = "printi32mem";
256   let MIOperandInfo = (ops GR32_TC, i8imm, GR32_TC, i32imm, i8imm);
257   let ParserMatchClass = X86MemAsmOperand;
258 }
259
260
261 let ParserMatchClass = X86AbsMemAsmOperand,
262     PrintMethod = "print_pcrel_imm" in {
263 def i32imm_pcrel : Operand<i32>;
264 def i16imm_pcrel : Operand<i16>;
265
266 def offset8 : Operand<i64>;
267 def offset16 : Operand<i64>;
268 def offset32 : Operand<i64>;
269 def offset64 : Operand<i64>;
270
271 // Branch targets have OtherVT type and print as pc-relative values.
272 def brtarget : Operand<OtherVT>;
273 def brtarget8 : Operand<OtherVT>;
274
275 }
276
277 def SSECC : Operand<i8> {
278   let PrintMethod = "printSSECC";
279 }
280
281 class ImmSExtAsmOperandClass : AsmOperandClass {
282   let SuperClasses = [ImmAsmOperand];
283   let RenderMethod = "addImmOperands";
284 }
285
286 // Sign-extended immediate classes. We don't need to define the full lattice
287 // here because there is no instruction with an ambiguity between ImmSExti64i32
288 // and ImmSExti32i8.
289 //
290 // The strange ranges come from the fact that the assembler always works with
291 // 64-bit immediates, but for a 16-bit target value we want to accept both "-1"
292 // (which will be a -1ULL), and "0xFF" (-1 in 16-bits).
293
294 // [0, 0x7FFFFFFF]                                            |
295 //   [0xFFFFFFFF80000000, 0xFFFFFFFFFFFFFFFF]
296 def ImmSExti64i32AsmOperand : ImmSExtAsmOperandClass {
297   let Name = "ImmSExti64i32";
298 }
299
300 // [0, 0x0000007F] | [0x000000000000FF80, 0x000000000000FFFF] |
301 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
302 def ImmSExti16i8AsmOperand : ImmSExtAsmOperandClass {
303   let Name = "ImmSExti16i8";
304   let SuperClasses = [ImmSExti64i32AsmOperand];
305 }
306
307 // [0, 0x0000007F] | [0x00000000FFFFFF80, 0x00000000FFFFFFFF] |
308 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
309 def ImmSExti32i8AsmOperand : ImmSExtAsmOperandClass {
310   let Name = "ImmSExti32i8";
311 }
312
313 // [0, 0x0000007F]                                            |
314 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
315 def ImmSExti64i8AsmOperand : ImmSExtAsmOperandClass {
316   let Name = "ImmSExti64i8";
317   let SuperClasses = [ImmSExti16i8AsmOperand, ImmSExti32i8AsmOperand,
318                       ImmSExti64i32AsmOperand];
319 }
320
321 // A couple of more descriptive operand definitions.
322 // 16-bits but only 8 bits are significant.
323 def i16i8imm  : Operand<i16> {
324   let ParserMatchClass = ImmSExti16i8AsmOperand;
325 }
326 // 32-bits but only 8 bits are significant.
327 def i32i8imm  : Operand<i32> {
328   let ParserMatchClass = ImmSExti32i8AsmOperand;
329 }
330
331 //===----------------------------------------------------------------------===//
332 // X86 Complex Pattern Definitions.
333 //
334
335 // Define X86 specific addressing mode.
336 def addr      : ComplexPattern<iPTR, 5, "SelectAddr", [], [SDNPWantParent]>;
337 def lea32addr : ComplexPattern<i32, 5, "SelectLEAAddr",
338                                [add, sub, mul, X86mul_imm, shl, or, frameindex],
339                                []>;
340 def tls32addr : ComplexPattern<i32, 5, "SelectTLSADDRAddr",
341                                [tglobaltlsaddr], []>;
342
343 //===----------------------------------------------------------------------===//
344 // X86 Instruction Predicate Definitions.
345 def HasCMov      : Predicate<"Subtarget->hasCMov()">;
346 def NoCMov       : Predicate<"!Subtarget->hasCMov()">;
347
348 // FIXME: temporary hack to let codegen assert or generate poor code in case
349 // no AVX version of the desired intructions is present, this is better for
350 // incremental dev (without fallbacks it's easier to spot what's missing)
351 def HasMMX       : Predicate<"Subtarget->hasMMX() && !Subtarget->hasAVX()">;
352 def Has3DNow     : Predicate<"Subtarget->has3DNow()">;
353 def Has3DNowA    : Predicate<"Subtarget->has3DNowA()">;
354 def HasSSE1      : Predicate<"Subtarget->hasSSE1() && !Subtarget->hasAVX()">;
355 def HasSSE2      : Predicate<"Subtarget->hasSSE2() && !Subtarget->hasAVX()">;
356 def HasSSE3      : Predicate<"Subtarget->hasSSE3() && !Subtarget->hasAVX()">;
357 def HasSSSE3     : Predicate<"Subtarget->hasSSSE3() && !Subtarget->hasAVX()">;
358 def HasSSE41     : Predicate<"Subtarget->hasSSE41() && !Subtarget->hasAVX()">;
359 def HasSSE42     : Predicate<"Subtarget->hasSSE42() && !Subtarget->hasAVX()">;
360 def HasSSE4A     : Predicate<"Subtarget->hasSSE4A() && !Subtarget->hasAVX()">;
361
362 def HasAVX       : Predicate<"Subtarget->hasAVX()">;
363 def HasCLMUL     : Predicate<"Subtarget->hasCLMUL()">;
364 def HasFMA3      : Predicate<"Subtarget->hasFMA3()">;
365 def HasFMA4      : Predicate<"Subtarget->hasFMA4()">;
366 def FPStackf32   : Predicate<"!Subtarget->hasSSE1()">;
367 def FPStackf64   : Predicate<"!Subtarget->hasSSE2()">;
368 def In32BitMode  : Predicate<"!Subtarget->is64Bit()">;
369 def In64BitMode  : Predicate<"Subtarget->is64Bit()">;
370 def IsWin64      : Predicate<"Subtarget->isTargetWin64()">;
371 def NotWin64     : Predicate<"!Subtarget->isTargetWin64()">;
372 def SmallCode    : Predicate<"TM.getCodeModel() == CodeModel::Small">;
373 def KernelCode   : Predicate<"TM.getCodeModel() == CodeModel::Kernel">;
374 def FarData      : Predicate<"TM.getCodeModel() != CodeModel::Small &&"
375                              "TM.getCodeModel() != CodeModel::Kernel">;
376 def NearData     : Predicate<"TM.getCodeModel() == CodeModel::Small ||"
377                              "TM.getCodeModel() == CodeModel::Kernel">;
378 def IsStatic     : Predicate<"TM.getRelocationModel() == Reloc::Static">;
379 def IsNotPIC     : Predicate<"TM.getRelocationModel() != Reloc::PIC_">;
380 def OptForSize   : Predicate<"OptForSize">;
381 def OptForSpeed  : Predicate<"!OptForSize">;
382 def FastBTMem    : Predicate<"!Subtarget->isBTMemSlow()">;
383 def CallImmAddr  : Predicate<"Subtarget->IsLegalToCallImmediateAddr(TM)">;
384 def HasAES       : Predicate<"Subtarget->hasAES()">;
385
386 //===----------------------------------------------------------------------===//
387 // X86 Instruction Format Definitions.
388 //
389
390 include "X86InstrFormats.td"
391
392 //===----------------------------------------------------------------------===//
393 // Pattern fragments...
394 //
395
396 // X86 specific condition code. These correspond to CondCode in
397 // X86InstrInfo.h. They must be kept in synch.
398 def X86_COND_A   : PatLeaf<(i8 0)>;  // alt. COND_NBE
399 def X86_COND_AE  : PatLeaf<(i8 1)>;  // alt. COND_NC
400 def X86_COND_B   : PatLeaf<(i8 2)>;  // alt. COND_C
401 def X86_COND_BE  : PatLeaf<(i8 3)>;  // alt. COND_NA
402 def X86_COND_E   : PatLeaf<(i8 4)>;  // alt. COND_Z
403 def X86_COND_G   : PatLeaf<(i8 5)>;  // alt. COND_NLE
404 def X86_COND_GE  : PatLeaf<(i8 6)>;  // alt. COND_NL
405 def X86_COND_L   : PatLeaf<(i8 7)>;  // alt. COND_NGE
406 def X86_COND_LE  : PatLeaf<(i8 8)>;  // alt. COND_NG
407 def X86_COND_NE  : PatLeaf<(i8 9)>;  // alt. COND_NZ
408 def X86_COND_NO  : PatLeaf<(i8 10)>;
409 def X86_COND_NP  : PatLeaf<(i8 11)>; // alt. COND_PO
410 def X86_COND_NS  : PatLeaf<(i8 12)>;
411 def X86_COND_O   : PatLeaf<(i8 13)>;
412 def X86_COND_P   : PatLeaf<(i8 14)>; // alt. COND_PE
413 def X86_COND_S   : PatLeaf<(i8 15)>;
414
415 def immSext8 : PatLeaf<(imm), [{ return immSext8(N); }]>;
416
417 def i16immSExt8  : PatLeaf<(i16 immSext8)>;
418 def i32immSExt8  : PatLeaf<(i32 immSext8)>;
419
420 // Helper fragments for loads.
421 // It's always safe to treat a anyext i16 load as a i32 load if the i16 is
422 // known to be 32-bit aligned or better. Ditto for i8 to i16.
423 def loadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{
424   LoadSDNode *LD = cast<LoadSDNode>(N);
425   ISD::LoadExtType ExtType = LD->getExtensionType();
426   if (ExtType == ISD::NON_EXTLOAD)
427     return true;
428   if (ExtType == ISD::EXTLOAD)
429     return LD->getAlignment() >= 2 && !LD->isVolatile();
430   return false;
431 }]>;
432
433 def loadi16_anyext : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)),[{
434   LoadSDNode *LD = cast<LoadSDNode>(N);
435   ISD::LoadExtType ExtType = LD->getExtensionType();
436   if (ExtType == ISD::EXTLOAD)
437     return LD->getAlignment() >= 2 && !LD->isVolatile();
438   return false;
439 }]>;
440
441 def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
442   LoadSDNode *LD = cast<LoadSDNode>(N);
443   ISD::LoadExtType ExtType = LD->getExtensionType();
444   if (ExtType == ISD::NON_EXTLOAD)
445     return true;
446   if (ExtType == ISD::EXTLOAD)
447     return LD->getAlignment() >= 4 && !LD->isVolatile();
448   return false;
449 }]>;
450
451 def loadi8  : PatFrag<(ops node:$ptr), (i8  (load node:$ptr))>;
452 def loadi64 : PatFrag<(ops node:$ptr), (i64 (load node:$ptr))>;
453 def loadf32 : PatFrag<(ops node:$ptr), (f32 (load node:$ptr))>;
454 def loadf64 : PatFrag<(ops node:$ptr), (f64 (load node:$ptr))>;
455 def loadf80 : PatFrag<(ops node:$ptr), (f80 (load node:$ptr))>;
456
457 def sextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
458 def sextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
459 def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
460
461 def zextloadi8i1   : PatFrag<(ops node:$ptr), (i8  (zextloadi1 node:$ptr))>;
462 def zextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
463 def zextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
464 def zextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
465 def zextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
466 def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
467
468 def extloadi8i1    : PatFrag<(ops node:$ptr), (i8  (extloadi1 node:$ptr))>;
469 def extloadi16i1   : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
470 def extloadi32i1   : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
471 def extloadi16i8   : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
472 def extloadi32i8   : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
473 def extloadi32i16  : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
474
475
476 // An 'and' node with a single use.
477 def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
478   return N->hasOneUse();
479 }]>;
480 // An 'srl' node with a single use.
481 def srl_su : PatFrag<(ops node:$lhs, node:$rhs), (srl node:$lhs, node:$rhs), [{
482   return N->hasOneUse();
483 }]>;
484 // An 'trunc' node with a single use.
485 def trunc_su : PatFrag<(ops node:$src), (trunc node:$src), [{
486   return N->hasOneUse();
487 }]>;
488
489 // Treat an 'or' node is as an 'add' if the or'ed bits are known to be zero.
490 def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
491   if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1)))
492     return CurDAG->MaskedValueIsZero(N->getOperand(0), CN->getAPIntValue());
493
494   unsigned BitWidth = N->getValueType(0).getScalarType().getSizeInBits();
495   APInt Mask = APInt::getAllOnesValue(BitWidth);
496   APInt KnownZero0, KnownOne0;
497   CurDAG->ComputeMaskedBits(N->getOperand(0), Mask, KnownZero0, KnownOne0, 0);
498   APInt KnownZero1, KnownOne1;
499   CurDAG->ComputeMaskedBits(N->getOperand(1), Mask, KnownZero1, KnownOne1, 0);
500   return (~KnownZero0 & ~KnownZero1) == 0;
501 }]>;
502
503 //===----------------------------------------------------------------------===//
504 // Instruction list.
505 //
506
507 // ADJCALLSTACKDOWN/UP implicitly use/def ESP because they may be expanded into
508 // a stack adjustment and the codegen must know that they may modify the stack
509 // pointer before prolog-epilog rewriting occurs.
510 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
511 // sub / add which can clobber EFLAGS.
512 let Defs = [ESP, EFLAGS], Uses = [ESP] in {
513 def ADJCALLSTACKDOWN32 : I<0, Pseudo, (outs), (ins i32imm:$amt),
514                            "#ADJCALLSTACKDOWN",
515                            [(X86callseq_start timm:$amt)]>,
516                           Requires<[In32BitMode]>;
517 def ADJCALLSTACKUP32   : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
518                            "#ADJCALLSTACKUP",
519                            [(X86callseq_end timm:$amt1, timm:$amt2)]>,
520                           Requires<[In32BitMode]>;
521 }
522
523 // x86-64 va_start lowering magic.
524 let usesCustomInserter = 1 in {
525 def VASTART_SAVE_XMM_REGS : I<0, Pseudo,
526                               (outs),
527                               (ins GR8:$al,
528                                    i64imm:$regsavefi, i64imm:$offset,
529                                    variable_ops),
530                               "#VASTART_SAVE_XMM_REGS $al, $regsavefi, $offset",
531                               [(X86vastart_save_xmm_regs GR8:$al,
532                                                          imm:$regsavefi,
533                                                          imm:$offset)]>;
534
535 // Dynamic stack allocation yields _alloca call for Cygwin/Mingw targets.  Calls
536 // to _alloca is needed to probe the stack when allocating more than 4k bytes in
537 // one go. Touching the stack at 4K increments is necessary to ensure that the
538 // guard pages used by the OS virtual memory manager are allocated in correct
539 // sequence.
540 // The main point of having separate instruction are extra unmodelled effects
541 // (compared to ordinary calls) like stack pointer change.
542
543 let Defs = [EAX, ESP, EFLAGS], Uses = [ESP] in
544   def MINGW_ALLOCA : I<0, Pseudo, (outs), (ins),
545                        "# dynamic stack allocation",
546                        [(X86MingwAlloca)]>;
547 }
548
549 // Nop
550 let neverHasSideEffects = 1 in {
551   def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", []>;
552   def NOOPW : I<0x1f, MRM0m, (outs), (ins i16mem:$zero),
553                 "nop{w}\t$zero", []>, TB, OpSize;
554   def NOOPL : I<0x1f, MRM0m, (outs), (ins i32mem:$zero),
555                 "nop{l}\t$zero", []>, TB;
556 }
557
558 // PIC base construction.  This expands to code that looks like this:
559 //     call  $next_inst
560 //     popl %destreg"
561 let neverHasSideEffects = 1, isNotDuplicable = 1, Uses = [ESP] in
562   def MOVPC32r : Ii32<0xE8, Pseudo, (outs GR32:$reg), (ins i32imm:$label),
563                       "", []>;
564
565
566 // Constructing a stack frame.
567 def ENTER : Ii16<0xC8, RawFrmImm8, (outs), (ins i16imm:$len, i8imm:$lvl),
568                  "enter\t$len, $lvl", []>;
569
570 let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, neverHasSideEffects=1 in
571 def LEAVE    : I<0xC9, RawFrm,
572                  (outs), (ins), "leave", []>, Requires<[In32BitMode]>;
573
574 //===----------------------------------------------------------------------===//
575 //  Miscellaneous Instructions...
576 //
577 def POPCNT16rr : I<0xB8, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
578                    "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
579 let mayLoad = 1 in
580 def POPCNT16rm : I<0xB8, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
581                    "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
582 def POPCNT32rr : I<0xB8, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
583                    "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
584 let mayLoad = 1 in
585 def POPCNT32rm : I<0xB8, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
586                    "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
587
588 let Defs = [ESP], Uses = [ESP], neverHasSideEffects=1 in {
589 let mayLoad = 1 in {
590 def POP16r  : I<0x58, AddRegFrm, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
591   OpSize;
592 def POP32r  : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
593 def POP16rmr: I<0x8F, MRM0r, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
594   OpSize;
595 def POP16rmm: I<0x8F, MRM0m, (outs i16mem:$dst), (ins), "pop{w}\t$dst", []>,
596   OpSize;
597 def POP32rmr: I<0x8F, MRM0r, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
598 def POP32rmm: I<0x8F, MRM0m, (outs i32mem:$dst), (ins), "pop{l}\t$dst", []>;
599 }
600
601 let mayStore = 1 in {
602 def PUSH16r  : I<0x50, AddRegFrm, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
603   OpSize;
604 def PUSH32r  : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
605 def PUSH16rmr: I<0xFF, MRM6r, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
606   OpSize;
607 def PUSH16rmm: I<0xFF, MRM6m, (outs), (ins i16mem:$src), "push{w}\t$src",[]>,
608   OpSize;
609 def PUSH32rmr: I<0xFF, MRM6r, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
610 def PUSH32rmm: I<0xFF, MRM6m, (outs), (ins i32mem:$src), "push{l}\t$src",[]>;
611 }
612 }
613
614 let Defs = [ESP], Uses = [ESP], neverHasSideEffects = 1, mayStore = 1 in {
615 def PUSHi8   : Ii8<0x6a, RawFrm, (outs), (ins i32i8imm:$imm), 
616                       "push{l}\t$imm", []>;
617 def PUSHi16  : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm), 
618                       "push{w}\t$imm", []>, OpSize;
619 def PUSHi32  : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm), 
620                       "push{l}\t$imm", []>;
621 }
622
623 let Defs = [ESP, EFLAGS], Uses = [ESP], mayLoad = 1, neverHasSideEffects=1 in {
624 def POPF16   : I<0x9D, RawFrm, (outs), (ins), "popf{w}", []>, OpSize;
625 def POPF32   : I<0x9D, RawFrm, (outs), (ins), "popf{l|d}", []>,
626                Requires<[In32BitMode]>;
627 }
628 let Defs = [ESP], Uses = [ESP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in {
629 def PUSHF16  : I<0x9C, RawFrm, (outs), (ins), "pushf{w}", []>, OpSize;
630 def PUSHF32  : I<0x9C, RawFrm, (outs), (ins), "pushf{l|d}", []>,
631                Requires<[In32BitMode]>;
632 }
633
634 let Defs = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP], Uses = [ESP],
635     mayLoad=1, neverHasSideEffects=1 in {
636 def POPA32   : I<0x61, RawFrm, (outs), (ins), "popa{l}", []>,
637                Requires<[In32BitMode]>;
638 }
639 let Defs = [ESP], Uses = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP],
640     mayStore=1, neverHasSideEffects=1 in {
641 def PUSHA32  : I<0x60, RawFrm, (outs), (ins), "pusha{l}", []>,
642                Requires<[In32BitMode]>;
643 }
644
645 let Uses = [EFLAGS], Constraints = "$src = $dst" in     // GR32 = bswap GR32
646   def BSWAP32r : I<0xC8, AddRegFrm,
647                    (outs GR32:$dst), (ins GR32:$src),
648                    "bswap{l}\t$dst", 
649                    [(set GR32:$dst, (bswap GR32:$src))]>, TB;
650
651
652 // Bit scan instructions.
653 let Defs = [EFLAGS] in {
654 def BSF16rr  : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
655                  "bsf{w}\t{$src, $dst|$dst, $src}",
656                  [(set GR16:$dst, EFLAGS, (X86bsf GR16:$src))]>, TB, OpSize;
657 def BSF16rm  : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
658                  "bsf{w}\t{$src, $dst|$dst, $src}",
659                  [(set GR16:$dst, EFLAGS, (X86bsf (loadi16 addr:$src)))]>, TB,
660                  OpSize;
661 def BSF32rr  : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
662                  "bsf{l}\t{$src, $dst|$dst, $src}",
663                  [(set GR32:$dst, EFLAGS, (X86bsf GR32:$src))]>, TB;
664 def BSF32rm  : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
665                  "bsf{l}\t{$src, $dst|$dst, $src}",
666                  [(set GR32:$dst, EFLAGS, (X86bsf (loadi32 addr:$src)))]>, TB;
667
668 def BSR16rr  : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
669                  "bsr{w}\t{$src, $dst|$dst, $src}",
670                  [(set GR16:$dst, EFLAGS, (X86bsr GR16:$src))]>, TB, OpSize;
671 def BSR16rm  : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
672                  "bsr{w}\t{$src, $dst|$dst, $src}",
673                  [(set GR16:$dst, EFLAGS, (X86bsr (loadi16 addr:$src)))]>, TB,
674                  OpSize;
675 def BSR32rr  : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
676                  "bsr{l}\t{$src, $dst|$dst, $src}",
677                  [(set GR32:$dst, EFLAGS, (X86bsr GR32:$src))]>, TB;
678 def BSR32rm  : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
679                  "bsr{l}\t{$src, $dst|$dst, $src}",
680                  [(set GR32:$dst, EFLAGS, (X86bsr (loadi32 addr:$src)))]>, TB;
681 } // Defs = [EFLAGS]
682
683 let neverHasSideEffects = 1 in
684 def LEA16r   : I<0x8D, MRMSrcMem,
685                  (outs GR16:$dst), (ins i32mem:$src),
686                  "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize;
687 let isReMaterializable = 1 in
688 def LEA32r   : I<0x8D, MRMSrcMem,
689                  (outs GR32:$dst), (ins i32mem:$src),
690                  "lea{l}\t{$src|$dst}, {$dst|$src}",
691                  [(set GR32:$dst, lea32addr:$src)]>, Requires<[In32BitMode]>;
692
693 let Defs = [ECX,EDI,ESI], Uses = [ECX,EDI,ESI], isCodeGenOnly = 1 in {
694 def REP_MOVSB : I<0xA4, RawFrm, (outs), (ins), "{rep;movsb|rep movsb}",
695                   [(X86rep_movs i8)]>, REP;
696 def REP_MOVSW : I<0xA5, RawFrm, (outs), (ins), "{rep;movsw|rep movsw}",
697                   [(X86rep_movs i16)]>, REP, OpSize;
698 def REP_MOVSD : I<0xA5, RawFrm, (outs), (ins), "{rep;movsl|rep movsd}",
699                   [(X86rep_movs i32)]>, REP;
700 }
701
702 // These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
703 let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in {
704 def MOVSB : I<0xA4, RawFrm, (outs), (ins), "{movsb}", []>;
705 def MOVSW : I<0xA5, RawFrm, (outs), (ins), "{movsw}", []>, OpSize;
706 def MOVSD : I<0xA5, RawFrm, (outs), (ins), "{movsl|movsd}", []>;
707 }
708
709 let Defs = [ECX,EDI], Uses = [AL,ECX,EDI], isCodeGenOnly = 1 in
710 def REP_STOSB : I<0xAA, RawFrm, (outs), (ins), "{rep;stosb|rep stosb}",
711                   [(X86rep_stos i8)]>, REP;
712 let Defs = [ECX,EDI], Uses = [AX,ECX,EDI], isCodeGenOnly = 1 in
713 def REP_STOSW : I<0xAB, RawFrm, (outs), (ins), "{rep;stosw|rep stosw}",
714                   [(X86rep_stos i16)]>, REP, OpSize;
715 let Defs = [ECX,EDI], Uses = [EAX,ECX,EDI], isCodeGenOnly = 1 in
716 def REP_STOSD : I<0xAB, RawFrm, (outs), (ins), "{rep;stosl|rep stosd}",
717                   [(X86rep_stos i32)]>, REP;
718
719 // These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
720 let Defs = [EDI], Uses = [AL,EDI,EFLAGS] in
721 def STOSB : I<0xAA, RawFrm, (outs), (ins), "{stosb}", []>;
722 let Defs = [EDI], Uses = [AX,EDI,EFLAGS] in
723 def STOSW : I<0xAB, RawFrm, (outs), (ins), "{stosw}", []>, OpSize;
724 let Defs = [EDI], Uses = [EAX,EDI,EFLAGS] in
725 def STOSD : I<0xAB, RawFrm, (outs), (ins), "{stosl|stosd}", []>;
726
727 def SCAS8 : I<0xAE, RawFrm, (outs), (ins), "scas{b}", []>;
728 def SCAS16 : I<0xAF, RawFrm, (outs), (ins), "scas{w}", []>, OpSize;
729 def SCAS32 : I<0xAF, RawFrm, (outs), (ins), "scas{l}", []>;
730
731 def CMPS8 : I<0xA6, RawFrm, (outs), (ins), "cmps{b}", []>;
732 def CMPS16 : I<0xA7, RawFrm, (outs), (ins), "cmps{w}", []>, OpSize;
733 def CMPS32 : I<0xA7, RawFrm, (outs), (ins), "cmps{l}", []>;
734
735
736 //===----------------------------------------------------------------------===//
737 //  Move Instructions.
738 //
739 let neverHasSideEffects = 1 in {
740 def MOV8rr  : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src),
741                 "mov{b}\t{$src, $dst|$dst, $src}", []>;
742 def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
743                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
744 def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
745                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
746 }
747 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
748 def MOV8ri  : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src),
749                    "mov{b}\t{$src, $dst|$dst, $src}",
750                    [(set GR8:$dst, imm:$src)]>;
751 def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src),
752                    "mov{w}\t{$src, $dst|$dst, $src}",
753                    [(set GR16:$dst, imm:$src)]>, OpSize;
754 def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src),
755                    "mov{l}\t{$src, $dst|$dst, $src}",
756                    [(set GR32:$dst, imm:$src)]>;
757 }
758
759 def MOV8mi  : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src),
760                    "mov{b}\t{$src, $dst|$dst, $src}",
761                    [(store (i8 imm:$src), addr:$dst)]>;
762 def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src),
763                    "mov{w}\t{$src, $dst|$dst, $src}",
764                    [(store (i16 imm:$src), addr:$dst)]>, OpSize;
765 def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src),
766                    "mov{l}\t{$src, $dst|$dst, $src}",
767                    [(store (i32 imm:$src), addr:$dst)]>;
768
769 /// moffs8, moffs16 and moffs32 versions of moves.  The immediate is a
770 /// 32-bit offset from the PC.  These are only valid in x86-32 mode.
771 def MOV8o8a : Ii32 <0xA0, RawFrm, (outs), (ins offset8:$src),
772                    "mov{b}\t{$src, %al|%al, $src}", []>,
773                    Requires<[In32BitMode]>;
774 def MOV16o16a : Ii32 <0xA1, RawFrm, (outs), (ins offset16:$src),
775                       "mov{w}\t{$src, %ax|%ax, $src}", []>, OpSize,
776                      Requires<[In32BitMode]>;
777 def MOV32o32a : Ii32 <0xA1, RawFrm, (outs), (ins offset32:$src),
778                       "mov{l}\t{$src, %eax|%eax, $src}", []>,
779                      Requires<[In32BitMode]>;
780 def MOV8ao8 : Ii32 <0xA2, RawFrm, (outs offset8:$dst), (ins),
781                    "mov{b}\t{%al, $dst|$dst, %al}", []>,
782                   Requires<[In32BitMode]>;
783 def MOV16ao16 : Ii32 <0xA3, RawFrm, (outs offset16:$dst), (ins),
784                       "mov{w}\t{%ax, $dst|$dst, %ax}", []>, OpSize,
785                      Requires<[In32BitMode]>;
786 def MOV32ao32 : Ii32 <0xA3, RawFrm, (outs offset32:$dst), (ins),
787                       "mov{l}\t{%eax, $dst|$dst, %eax}", []>,
788                      Requires<[In32BitMode]>;
789                       
790
791 let isCodeGenOnly = 1 in {
792 def MOV8rr_REV : I<0x8A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src),
793                    "mov{b}\t{$src, $dst|$dst, $src}", []>;
794 def MOV16rr_REV : I<0x8B, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
795                     "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
796 def MOV32rr_REV : I<0x8B, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
797                     "mov{l}\t{$src, $dst|$dst, $src}", []>;
798 }
799
800 let canFoldAsLoad = 1, isReMaterializable = 1 in {
801 def MOV8rm  : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src),
802                 "mov{b}\t{$src, $dst|$dst, $src}",
803                 [(set GR8:$dst, (loadi8 addr:$src))]>;
804 def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
805                 "mov{w}\t{$src, $dst|$dst, $src}",
806                 [(set GR16:$dst, (loadi16 addr:$src))]>, OpSize;
807 def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
808                 "mov{l}\t{$src, $dst|$dst, $src}",
809                 [(set GR32:$dst, (loadi32 addr:$src))]>;
810 }
811
812 def MOV8mr  : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src),
813                 "mov{b}\t{$src, $dst|$dst, $src}",
814                 [(store GR8:$src, addr:$dst)]>;
815 def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
816                 "mov{w}\t{$src, $dst|$dst, $src}",
817                 [(store GR16:$src, addr:$dst)]>, OpSize;
818 def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
819                 "mov{l}\t{$src, $dst|$dst, $src}",
820                 [(store GR32:$src, addr:$dst)]>;
821
822 /// Versions of MOV32rr, MOV32rm, and MOV32mr for i32mem_TC and GR32_TC.
823 let isCodeGenOnly = 1 in {
824 let neverHasSideEffects = 1 in
825 def MOV32rr_TC : I<0x89, MRMDestReg, (outs GR32_TC:$dst), (ins GR32_TC:$src),
826                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
827
828 let mayLoad = 1,
829     canFoldAsLoad = 1, isReMaterializable = 1 in
830 def MOV32rm_TC : I<0x8B, MRMSrcMem, (outs GR32_TC:$dst), (ins i32mem_TC:$src),
831                 "mov{l}\t{$src, $dst|$dst, $src}",
832                 []>;
833
834 let mayStore = 1 in
835 def MOV32mr_TC : I<0x89, MRMDestMem, (outs), (ins i32mem_TC:$dst, GR32_TC:$src),
836                 "mov{l}\t{$src, $dst|$dst, $src}",
837                 []>;
838 }
839
840 // Versions of MOV8rr, MOV8mr, and MOV8rm that use i8mem_NOREX and GR8_NOREX so
841 // that they can be used for copying and storing h registers, which can't be
842 // encoded when a REX prefix is present.
843 let isCodeGenOnly = 1 in {
844 let neverHasSideEffects = 1 in
845 def MOV8rr_NOREX : I<0x88, MRMDestReg,
846                      (outs GR8_NOREX:$dst), (ins GR8_NOREX:$src),
847                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
848 let mayStore = 1 in
849 def MOV8mr_NOREX : I<0x88, MRMDestMem,
850                      (outs), (ins i8mem_NOREX:$dst, GR8_NOREX:$src),
851                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
852 let mayLoad = 1,
853     canFoldAsLoad = 1, isReMaterializable = 1 in
854 def MOV8rm_NOREX : I<0x8A, MRMSrcMem,
855                      (outs GR8_NOREX:$dst), (ins i8mem_NOREX:$src),
856                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
857 }
858
859 //===----------------------------------------------------------------------===//
860 //  Fixed-Register Multiplication and Division Instructions...
861 //
862
863 // Extra precision multiplication
864
865 // AL is really implied by AX, but the registers in Defs must match the
866 // SDNode results (i8, i32).
867 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
868 def MUL8r  : I<0xF6, MRM4r, (outs),  (ins GR8:$src), "mul{b}\t$src",
869                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
870                // This probably ought to be moved to a def : Pat<> if the
871                // syntax can be accepted.
872                [(set AL, (mul AL, GR8:$src)),
873                 (implicit EFLAGS)]>;     // AL,AH = AL*GR8
874
875 let Defs = [AX,DX,EFLAGS], Uses = [AX], neverHasSideEffects = 1 in
876 def MUL16r : I<0xF7, MRM4r, (outs),  (ins GR16:$src),
877                "mul{w}\t$src", 
878                []>, OpSize;    // AX,DX = AX*GR16
879
880 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], neverHasSideEffects = 1 in
881 def MUL32r : I<0xF7, MRM4r, (outs),  (ins GR32:$src),
882                "mul{l}\t$src",
883                []>; // EAX,EDX = EAX*GR32
884
885 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
886 def MUL8m  : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
887                "mul{b}\t$src",
888                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
889                // This probably ought to be moved to a def : Pat<> if the
890                // syntax can be accepted.
891                [(set AL, (mul AL, (loadi8 addr:$src))),
892                 (implicit EFLAGS)]>;   // AL,AH = AL*[mem8]
893
894 let mayLoad = 1, neverHasSideEffects = 1 in {
895 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
896 def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
897                "mul{w}\t$src",
898                []>, OpSize; // AX,DX = AX*[mem16]
899
900 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
901 def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
902               "mul{l}\t$src",
903               []>;          // EAX,EDX = EAX*[mem32]
904 }
905
906 let neverHasSideEffects = 1 in {
907 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
908 def IMUL8r  : I<0xF6, MRM5r, (outs),  (ins GR8:$src), "imul{b}\t$src", []>;
909               // AL,AH = AL*GR8
910 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
911 def IMUL16r : I<0xF7, MRM5r, (outs),  (ins GR16:$src), "imul{w}\t$src", []>,
912               OpSize;    // AX,DX = AX*GR16
913 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
914 def IMUL32r : I<0xF7, MRM5r, (outs),  (ins GR32:$src), "imul{l}\t$src", []>;
915               // EAX,EDX = EAX*GR32
916 let mayLoad = 1 in {
917 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
918 def IMUL8m  : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
919                 "imul{b}\t$src", []>;    // AL,AH = AL*[mem8]
920 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
921 def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
922                 "imul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
923 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
924 def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
925                 "imul{l}\t$src", []>;  // EAX,EDX = EAX*[mem32]
926 }
927 } // neverHasSideEffects
928
929 // unsigned division/remainder
930 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
931 def DIV8r  : I<0xF6, MRM6r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
932                "div{b}\t$src", []>;
933 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
934 def DIV16r : I<0xF7, MRM6r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
935                "div{w}\t$src", []>, OpSize;
936 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
937 def DIV32r : I<0xF7, MRM6r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
938                "div{l}\t$src", []>;
939 let mayLoad = 1 in {
940 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
941 def DIV8m  : I<0xF6, MRM6m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
942                "div{b}\t$src", []>;
943 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
944 def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
945                "div{w}\t$src", []>, OpSize;
946 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
947                                                     // EDX:EAX/[mem32] = EAX,EDX
948 def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),
949                "div{l}\t$src", []>;
950 }
951
952 // Signed division/remainder.
953 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
954 def IDIV8r : I<0xF6, MRM7r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
955                "idiv{b}\t$src", []>;
956 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
957 def IDIV16r: I<0xF7, MRM7r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
958                "idiv{w}\t$src", []>, OpSize;
959 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
960 def IDIV32r: I<0xF7, MRM7r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
961                "idiv{l}\t$src", []>;
962 let mayLoad = 1, mayLoad = 1 in {
963 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
964 def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
965                "idiv{b}\t$src", []>;
966 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
967 def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
968                "idiv{w}\t$src", []>, OpSize;
969 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
970 def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src), 
971                                                     // EDX:EAX/[mem32] = EAX,EDX
972                "idiv{l}\t$src", []>;
973 }
974
975 //===----------------------------------------------------------------------===//
976 //  Two address Instructions.
977 //
978 let Constraints = "$src1 = $dst" in {
979
980 // Conditional moves
981 let Uses = [EFLAGS] in {
982
983 let Predicates = [HasCMov] in {
984 let isCommutable = 1 in {
985 def CMOVB16rr : I<0x42, MRMSrcReg,       // if <u, GR16 = GR16
986                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
987                   "cmovb{w}\t{$src2, $dst|$dst, $src2}",
988                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
989                                    X86_COND_B, EFLAGS))]>,
990                   TB, OpSize;
991 def CMOVB32rr : I<0x42, MRMSrcReg,       // if <u, GR32 = GR32
992                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
993                   "cmovb{l}\t{$src2, $dst|$dst, $src2}",
994                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
995                                    X86_COND_B, EFLAGS))]>,
996                    TB;
997 def CMOVAE16rr: I<0x43, MRMSrcReg,       // if >=u, GR16 = GR16
998                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
999                   "cmovae{w}\t{$src2, $dst|$dst, $src2}",
1000                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1001                                    X86_COND_AE, EFLAGS))]>,
1002                    TB, OpSize;
1003 def CMOVAE32rr: I<0x43, MRMSrcReg,       // if >=u, GR32 = GR32
1004                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1005                   "cmovae{l}\t{$src2, $dst|$dst, $src2}",
1006                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1007                                    X86_COND_AE, EFLAGS))]>,
1008                    TB;
1009 def CMOVE16rr : I<0x44, MRMSrcReg,       // if ==, GR16 = GR16
1010                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1011                   "cmove{w}\t{$src2, $dst|$dst, $src2}",
1012                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1013                                    X86_COND_E, EFLAGS))]>,
1014                    TB, OpSize;
1015 def CMOVE32rr : I<0x44, MRMSrcReg,       // if ==, GR32 = GR32
1016                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1017                   "cmove{l}\t{$src2, $dst|$dst, $src2}",
1018                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1019                                    X86_COND_E, EFLAGS))]>,
1020                    TB;
1021 def CMOVNE16rr: I<0x45, MRMSrcReg,       // if !=, GR16 = GR16
1022                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1023                   "cmovne{w}\t{$src2, $dst|$dst, $src2}",
1024                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1025                                    X86_COND_NE, EFLAGS))]>,
1026                    TB, OpSize;
1027 def CMOVNE32rr: I<0x45, MRMSrcReg,       // if !=, GR32 = GR32
1028                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1029                   "cmovne{l}\t{$src2, $dst|$dst, $src2}",
1030                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1031                                    X86_COND_NE, EFLAGS))]>,
1032                    TB;
1033 def CMOVBE16rr: I<0x46, MRMSrcReg,       // if <=u, GR16 = GR16
1034                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1035                   "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
1036                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1037                                    X86_COND_BE, EFLAGS))]>,
1038                    TB, OpSize;
1039 def CMOVBE32rr: I<0x46, MRMSrcReg,       // if <=u, GR32 = GR32
1040                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1041                   "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
1042                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1043                                    X86_COND_BE, EFLAGS))]>,
1044                    TB;
1045 def CMOVA16rr : I<0x47, MRMSrcReg,       // if >u, GR16 = GR16
1046                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1047                   "cmova{w}\t{$src2, $dst|$dst, $src2}",
1048                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1049                                    X86_COND_A, EFLAGS))]>,
1050                    TB, OpSize;
1051 def CMOVA32rr : I<0x47, MRMSrcReg,       // if >u, GR32 = GR32
1052                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1053                   "cmova{l}\t{$src2, $dst|$dst, $src2}",
1054                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1055                                    X86_COND_A, EFLAGS))]>,
1056                    TB;
1057 def CMOVL16rr : I<0x4C, MRMSrcReg,       // if <s, GR16 = GR16
1058                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1059                   "cmovl{w}\t{$src2, $dst|$dst, $src2}",
1060                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1061                                    X86_COND_L, EFLAGS))]>,
1062                    TB, OpSize;
1063 def CMOVL32rr : I<0x4C, MRMSrcReg,       // if <s, GR32 = GR32
1064                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1065                   "cmovl{l}\t{$src2, $dst|$dst, $src2}",
1066                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1067                                    X86_COND_L, EFLAGS))]>,
1068                    TB;
1069 def CMOVGE16rr: I<0x4D, MRMSrcReg,       // if >=s, GR16 = GR16
1070                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1071                   "cmovge{w}\t{$src2, $dst|$dst, $src2}",
1072                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1073                                    X86_COND_GE, EFLAGS))]>,
1074                    TB, OpSize;
1075 def CMOVGE32rr: I<0x4D, MRMSrcReg,       // if >=s, GR32 = GR32
1076                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1077                   "cmovge{l}\t{$src2, $dst|$dst, $src2}",
1078                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1079                                    X86_COND_GE, EFLAGS))]>,
1080                    TB;
1081 def CMOVLE16rr: I<0x4E, MRMSrcReg,       // if <=s, GR16 = GR16
1082                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1083                   "cmovle{w}\t{$src2, $dst|$dst, $src2}",
1084                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1085                                    X86_COND_LE, EFLAGS))]>,
1086                    TB, OpSize;
1087 def CMOVLE32rr: I<0x4E, MRMSrcReg,       // if <=s, GR32 = GR32
1088                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1089                   "cmovle{l}\t{$src2, $dst|$dst, $src2}",
1090                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1091                                    X86_COND_LE, EFLAGS))]>,
1092                    TB;
1093 def CMOVG16rr : I<0x4F, MRMSrcReg,       // if >s, GR16 = GR16
1094                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1095                   "cmovg{w}\t{$src2, $dst|$dst, $src2}",
1096                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1097                                    X86_COND_G, EFLAGS))]>,
1098                    TB, OpSize;
1099 def CMOVG32rr : I<0x4F, MRMSrcReg,       // if >s, GR32 = GR32
1100                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1101                   "cmovg{l}\t{$src2, $dst|$dst, $src2}",
1102                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1103                                    X86_COND_G, EFLAGS))]>,
1104                    TB;
1105 def CMOVS16rr : I<0x48, MRMSrcReg,       // if signed, GR16 = GR16
1106                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1107                   "cmovs{w}\t{$src2, $dst|$dst, $src2}",
1108                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1109                                    X86_COND_S, EFLAGS))]>,
1110                   TB, OpSize;
1111 def CMOVS32rr : I<0x48, MRMSrcReg,       // if signed, GR32 = GR32
1112                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1113                   "cmovs{l}\t{$src2, $dst|$dst, $src2}",
1114                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1115                                    X86_COND_S, EFLAGS))]>,
1116                   TB;
1117 def CMOVNS16rr: I<0x49, MRMSrcReg,       // if !signed, GR16 = GR16
1118                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1119                   "cmovns{w}\t{$src2, $dst|$dst, $src2}",
1120                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1121                                    X86_COND_NS, EFLAGS))]>,
1122                   TB, OpSize;
1123 def CMOVNS32rr: I<0x49, MRMSrcReg,       // if !signed, GR32 = GR32
1124                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1125                   "cmovns{l}\t{$src2, $dst|$dst, $src2}",
1126                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1127                                    X86_COND_NS, EFLAGS))]>,
1128                   TB;
1129 def CMOVP16rr : I<0x4A, MRMSrcReg,       // if parity, GR16 = GR16
1130                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1131                   "cmovp{w}\t{$src2, $dst|$dst, $src2}",
1132                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1133                                    X86_COND_P, EFLAGS))]>,
1134                   TB, OpSize;
1135 def CMOVP32rr : I<0x4A, MRMSrcReg,       // if parity, GR32 = GR32
1136                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1137                   "cmovp{l}\t{$src2, $dst|$dst, $src2}",
1138                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1139                                    X86_COND_P, EFLAGS))]>,
1140                   TB;
1141 def CMOVNP16rr : I<0x4B, MRMSrcReg,       // if !parity, GR16 = GR16
1142                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1143                   "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
1144                    [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1145                                     X86_COND_NP, EFLAGS))]>,
1146                   TB, OpSize;
1147 def CMOVNP32rr : I<0x4B, MRMSrcReg,       // if !parity, GR32 = GR32
1148                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1149                   "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
1150                    [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1151                                     X86_COND_NP, EFLAGS))]>,
1152                   TB;
1153 def CMOVO16rr : I<0x40, MRMSrcReg,       // if overflow, GR16 = GR16
1154                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1155                   "cmovo{w}\t{$src2, $dst|$dst, $src2}",
1156                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1157                                    X86_COND_O, EFLAGS))]>,
1158                   TB, OpSize;
1159 def CMOVO32rr : I<0x40, MRMSrcReg,       // if overflow, GR32 = GR32
1160                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1161                   "cmovo{l}\t{$src2, $dst|$dst, $src2}",
1162                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1163                                    X86_COND_O, EFLAGS))]>,
1164                   TB;
1165 def CMOVNO16rr : I<0x41, MRMSrcReg,       // if !overflow, GR16 = GR16
1166                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1167                   "cmovno{w}\t{$src2, $dst|$dst, $src2}",
1168                    [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1169                                     X86_COND_NO, EFLAGS))]>,
1170                   TB, OpSize;
1171 def CMOVNO32rr : I<0x41, MRMSrcReg,       // if !overflow, GR32 = GR32
1172                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1173                   "cmovno{l}\t{$src2, $dst|$dst, $src2}",
1174                    [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1175                                     X86_COND_NO, EFLAGS))]>,
1176                   TB;
1177 } // isCommutable = 1
1178
1179 def CMOVB16rm : I<0x42, MRMSrcMem,       // if <u, GR16 = [mem16]
1180                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1181                   "cmovb{w}\t{$src2, $dst|$dst, $src2}",
1182                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1183                                    X86_COND_B, EFLAGS))]>,
1184                   TB, OpSize;
1185 def CMOVB32rm : I<0x42, MRMSrcMem,       // if <u, GR32 = [mem32]
1186                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1187                   "cmovb{l}\t{$src2, $dst|$dst, $src2}",
1188                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1189                                    X86_COND_B, EFLAGS))]>,
1190                    TB;
1191 def CMOVAE16rm: I<0x43, MRMSrcMem,       // if >=u, GR16 = [mem16]
1192                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1193                   "cmovae{w}\t{$src2, $dst|$dst, $src2}",
1194                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1195                                    X86_COND_AE, EFLAGS))]>,
1196                    TB, OpSize;
1197 def CMOVAE32rm: I<0x43, MRMSrcMem,       // if >=u, GR32 = [mem32]
1198                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1199                   "cmovae{l}\t{$src2, $dst|$dst, $src2}",
1200                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1201                                    X86_COND_AE, EFLAGS))]>,
1202                    TB;
1203 def CMOVE16rm : I<0x44, MRMSrcMem,       // if ==, GR16 = [mem16]
1204                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1205                   "cmove{w}\t{$src2, $dst|$dst, $src2}",
1206                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1207                                    X86_COND_E, EFLAGS))]>,
1208                    TB, OpSize;
1209 def CMOVE32rm : I<0x44, MRMSrcMem,       // if ==, GR32 = [mem32]
1210                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1211                   "cmove{l}\t{$src2, $dst|$dst, $src2}",
1212                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1213                                    X86_COND_E, EFLAGS))]>,
1214                    TB;
1215 def CMOVNE16rm: I<0x45, MRMSrcMem,       // if !=, GR16 = [mem16]
1216                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1217                   "cmovne{w}\t{$src2, $dst|$dst, $src2}",
1218                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1219                                    X86_COND_NE, EFLAGS))]>,
1220                    TB, OpSize;
1221 def CMOVNE32rm: I<0x45, MRMSrcMem,       // if !=, GR32 = [mem32]
1222                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1223                   "cmovne{l}\t{$src2, $dst|$dst, $src2}",
1224                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1225                                    X86_COND_NE, EFLAGS))]>,
1226                    TB;
1227 def CMOVBE16rm: I<0x46, MRMSrcMem,       // if <=u, GR16 = [mem16]
1228                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1229                   "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
1230                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1231                                    X86_COND_BE, EFLAGS))]>,
1232                    TB, OpSize;
1233 def CMOVBE32rm: I<0x46, MRMSrcMem,       // if <=u, GR32 = [mem32]
1234                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1235                   "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
1236                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1237                                    X86_COND_BE, EFLAGS))]>,
1238                    TB;
1239 def CMOVA16rm : I<0x47, MRMSrcMem,       // if >u, GR16 = [mem16]
1240                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1241                   "cmova{w}\t{$src2, $dst|$dst, $src2}",
1242                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1243                                    X86_COND_A, EFLAGS))]>,
1244                    TB, OpSize;
1245 def CMOVA32rm : I<0x47, MRMSrcMem,       // if >u, GR32 = [mem32]
1246                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1247                   "cmova{l}\t{$src2, $dst|$dst, $src2}",
1248                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1249                                    X86_COND_A, EFLAGS))]>,
1250                    TB;
1251 def CMOVL16rm : I<0x4C, MRMSrcMem,       // if <s, GR16 = [mem16]
1252                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1253                   "cmovl{w}\t{$src2, $dst|$dst, $src2}",
1254                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1255                                    X86_COND_L, EFLAGS))]>,
1256                    TB, OpSize;
1257 def CMOVL32rm : I<0x4C, MRMSrcMem,       // if <s, GR32 = [mem32]
1258                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1259                   "cmovl{l}\t{$src2, $dst|$dst, $src2}",
1260                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1261                                    X86_COND_L, EFLAGS))]>,
1262                    TB;
1263 def CMOVGE16rm: I<0x4D, MRMSrcMem,       // if >=s, GR16 = [mem16]
1264                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1265                   "cmovge{w}\t{$src2, $dst|$dst, $src2}",
1266                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1267                                    X86_COND_GE, EFLAGS))]>,
1268                    TB, OpSize;
1269 def CMOVGE32rm: I<0x4D, MRMSrcMem,       // if >=s, GR32 = [mem32]
1270                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1271                   "cmovge{l}\t{$src2, $dst|$dst, $src2}",
1272                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1273                                    X86_COND_GE, EFLAGS))]>,
1274                    TB;
1275 def CMOVLE16rm: I<0x4E, MRMSrcMem,       // if <=s, GR16 = [mem16]
1276                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1277                   "cmovle{w}\t{$src2, $dst|$dst, $src2}",
1278                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1279                                    X86_COND_LE, EFLAGS))]>,
1280                    TB, OpSize;
1281 def CMOVLE32rm: I<0x4E, MRMSrcMem,       // if <=s, GR32 = [mem32]
1282                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1283                   "cmovle{l}\t{$src2, $dst|$dst, $src2}",
1284                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1285                                    X86_COND_LE, EFLAGS))]>,
1286                    TB;
1287 def CMOVG16rm : I<0x4F, MRMSrcMem,       // if >s, GR16 = [mem16]
1288                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1289                   "cmovg{w}\t{$src2, $dst|$dst, $src2}",
1290                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1291                                    X86_COND_G, EFLAGS))]>,
1292                    TB, OpSize;
1293 def CMOVG32rm : I<0x4F, MRMSrcMem,       // if >s, GR32 = [mem32]
1294                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1295                   "cmovg{l}\t{$src2, $dst|$dst, $src2}",
1296                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1297                                    X86_COND_G, EFLAGS))]>,
1298                    TB;
1299 def CMOVS16rm : I<0x48, MRMSrcMem,       // if signed, GR16 = [mem16]
1300                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1301                   "cmovs{w}\t{$src2, $dst|$dst, $src2}",
1302                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1303                                    X86_COND_S, EFLAGS))]>,
1304                   TB, OpSize;
1305 def CMOVS32rm : I<0x48, MRMSrcMem,       // if signed, GR32 = [mem32]
1306                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1307                   "cmovs{l}\t{$src2, $dst|$dst, $src2}",
1308                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1309                                    X86_COND_S, EFLAGS))]>,
1310                   TB;
1311 def CMOVNS16rm: I<0x49, MRMSrcMem,       // if !signed, GR16 = [mem16]
1312                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1313                   "cmovns{w}\t{$src2, $dst|$dst, $src2}",
1314                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1315                                    X86_COND_NS, EFLAGS))]>,
1316                   TB, OpSize;
1317 def CMOVNS32rm: I<0x49, MRMSrcMem,       // if !signed, GR32 = [mem32]
1318                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1319                   "cmovns{l}\t{$src2, $dst|$dst, $src2}",
1320                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1321                                    X86_COND_NS, EFLAGS))]>,
1322                   TB;
1323 def CMOVP16rm : I<0x4A, MRMSrcMem,       // if parity, GR16 = [mem16]
1324                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1325                   "cmovp{w}\t{$src2, $dst|$dst, $src2}",
1326                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1327                                    X86_COND_P, EFLAGS))]>,
1328                   TB, OpSize;
1329 def CMOVP32rm : I<0x4A, MRMSrcMem,       // if parity, GR32 = [mem32]
1330                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1331                   "cmovp{l}\t{$src2, $dst|$dst, $src2}",
1332                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1333                                    X86_COND_P, EFLAGS))]>,
1334                   TB;
1335 def CMOVNP16rm : I<0x4B, MRMSrcMem,       // if !parity, GR16 = [mem16]
1336                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1337                   "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
1338                    [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1339                                     X86_COND_NP, EFLAGS))]>,
1340                   TB, OpSize;
1341 def CMOVNP32rm : I<0x4B, MRMSrcMem,       // if !parity, GR32 = [mem32]
1342                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1343                   "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
1344                    [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1345                                     X86_COND_NP, EFLAGS))]>,
1346                   TB;
1347 def CMOVO16rm : I<0x40, MRMSrcMem,       // if overflow, GR16 = [mem16]
1348                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1349                   "cmovo{w}\t{$src2, $dst|$dst, $src2}",
1350                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1351                                    X86_COND_O, EFLAGS))]>,
1352                   TB, OpSize;
1353 def CMOVO32rm : I<0x40, MRMSrcMem,       // if overflow, GR32 = [mem32]
1354                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1355                   "cmovo{l}\t{$src2, $dst|$dst, $src2}",
1356                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1357                                    X86_COND_O, EFLAGS))]>,
1358                   TB;
1359 def CMOVNO16rm : I<0x41, MRMSrcMem,       // if !overflow, GR16 = [mem16]
1360                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1361                   "cmovno{w}\t{$src2, $dst|$dst, $src2}",
1362                    [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1363                                     X86_COND_NO, EFLAGS))]>,
1364                   TB, OpSize;
1365 def CMOVNO32rm : I<0x41, MRMSrcMem,       // if !overflow, GR32 = [mem32]
1366                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1367                   "cmovno{l}\t{$src2, $dst|$dst, $src2}",
1368                    [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1369                                     X86_COND_NO, EFLAGS))]>,
1370                   TB;
1371 } // Predicates = [HasCMov]
1372
1373 // X86 doesn't have 8-bit conditional moves. Use a customInserter to
1374 // emit control flow. An alternative to this is to mark i8 SELECT as Promote,
1375 // however that requires promoting the operands, and can induce additional
1376 // i8 register pressure. Note that CMOV_GR8 is conservatively considered to
1377 // clobber EFLAGS, because if one of the operands is zero, the expansion
1378 // could involve an xor.
1379 let usesCustomInserter = 1, Constraints = "", Defs = [EFLAGS] in {
1380 def CMOV_GR8 : I<0, Pseudo,
1381                  (outs GR8:$dst), (ins GR8:$src1, GR8:$src2, i8imm:$cond),
1382                  "#CMOV_GR8 PSEUDO!",
1383                  [(set GR8:$dst, (X86cmov GR8:$src1, GR8:$src2,
1384                                           imm:$cond, EFLAGS))]>;
1385
1386 let Predicates = [NoCMov] in {
1387 def CMOV_GR32 : I<0, Pseudo,
1388                     (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$cond),
1389                     "#CMOV_GR32* PSEUDO!",
1390                     [(set GR32:$dst,
1391                       (X86cmov GR32:$src1, GR32:$src2, imm:$cond, EFLAGS))]>;
1392 def CMOV_GR16 : I<0, Pseudo,
1393                     (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$cond),
1394                     "#CMOV_GR16* PSEUDO!",
1395                     [(set GR16:$dst,
1396                       (X86cmov GR16:$src1, GR16:$src2, imm:$cond, EFLAGS))]>;
1397 def CMOV_RFP32 : I<0, Pseudo,
1398                     (outs RFP32:$dst),
1399                     (ins RFP32:$src1, RFP32:$src2, i8imm:$cond),
1400                     "#CMOV_RFP32 PSEUDO!",
1401                     [(set RFP32:$dst,
1402                       (X86cmov RFP32:$src1, RFP32:$src2, imm:$cond,
1403                                                   EFLAGS))]>;
1404 def CMOV_RFP64 : I<0, Pseudo,
1405                     (outs RFP64:$dst),
1406                     (ins RFP64:$src1, RFP64:$src2, i8imm:$cond),
1407                     "#CMOV_RFP64 PSEUDO!",
1408                     [(set RFP64:$dst,
1409                       (X86cmov RFP64:$src1, RFP64:$src2, imm:$cond,
1410                                                   EFLAGS))]>;
1411 def CMOV_RFP80 : I<0, Pseudo,
1412                     (outs RFP80:$dst),
1413                     (ins RFP80:$src1, RFP80:$src2, i8imm:$cond),
1414                     "#CMOV_RFP80 PSEUDO!",
1415                     [(set RFP80:$dst,
1416                       (X86cmov RFP80:$src1, RFP80:$src2, imm:$cond,
1417                                                   EFLAGS))]>;
1418 } // Predicates = [NoCMov]
1419 } // UsesCustomInserter = 1, Constraints = "", Defs = [EFLAGS] 
1420 } // Uses = [EFLAGS]
1421
1422
1423 // unary instructions
1424 let CodeSize = 2 in {
1425 let Defs = [EFLAGS] in {
1426 def NEG8r  : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src1),
1427                "neg{b}\t$dst",
1428                [(set GR8:$dst, (ineg GR8:$src1)),
1429                 (implicit EFLAGS)]>;
1430 def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
1431                "neg{w}\t$dst",
1432                [(set GR16:$dst, (ineg GR16:$src1)),
1433                 (implicit EFLAGS)]>, OpSize;
1434 def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
1435                "neg{l}\t$dst",
1436                [(set GR32:$dst, (ineg GR32:$src1)),
1437                 (implicit EFLAGS)]>;
1438                 
1439 let Constraints = "" in {
1440   def NEG8m  : I<0xF6, MRM3m, (outs), (ins i8mem :$dst),
1441                  "neg{b}\t$dst",
1442                  [(store (ineg (loadi8 addr:$dst)), addr:$dst),
1443                   (implicit EFLAGS)]>;
1444   def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst),
1445                  "neg{w}\t$dst",
1446                  [(store (ineg (loadi16 addr:$dst)), addr:$dst),
1447                   (implicit EFLAGS)]>, OpSize;
1448   def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst),
1449                  "neg{l}\t$dst",
1450                  [(store (ineg (loadi32 addr:$dst)), addr:$dst),
1451                   (implicit EFLAGS)]>;
1452 } // Constraints = ""
1453 } // Defs = [EFLAGS]
1454
1455 // Match xor -1 to not. Favors these over a move imm + xor to save code size.
1456 let AddedComplexity = 15 in {
1457 def NOT8r  : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src1),
1458                "not{b}\t$dst",
1459                [(set GR8:$dst, (not GR8:$src1))]>;
1460 def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
1461                "not{w}\t$dst",
1462                [(set GR16:$dst, (not GR16:$src1))]>, OpSize;
1463 def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
1464                "not{l}\t$dst",
1465                [(set GR32:$dst, (not GR32:$src1))]>;
1466 }
1467 let Constraints = "" in {
1468   def NOT8m  : I<0xF6, MRM2m, (outs), (ins i8mem :$dst),
1469                  "not{b}\t$dst",
1470                  [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
1471   def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst),
1472                  "not{w}\t$dst",
1473                  [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1474   def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst),
1475                  "not{l}\t$dst",
1476                  [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
1477 } // Constraints = ""
1478 } // CodeSize
1479
1480 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
1481 let Defs = [EFLAGS] in {
1482 let CodeSize = 2 in
1483 def INC8r  : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
1484                "inc{b}\t$dst",
1485                [(set GR8:$dst, EFLAGS, (X86inc_flag GR8:$src1))]>;
1486
1487 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {  // Can xform into LEA.
1488 def INC16r : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
1489                "inc{w}\t$dst",
1490                [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src1))]>,
1491              OpSize, Requires<[In32BitMode]>;
1492 def INC32r : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
1493                "inc{l}\t$dst",
1494                [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src1))]>,
1495              Requires<[In32BitMode]>;
1496 }
1497 let Constraints = "", CodeSize = 2 in {
1498   def INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
1499                [(store (add (loadi8 addr:$dst), 1), addr:$dst),
1500                 (implicit EFLAGS)]>;
1501   def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
1502                [(store (add (loadi16 addr:$dst), 1), addr:$dst),
1503                 (implicit EFLAGS)]>,
1504                OpSize, Requires<[In32BitMode]>;
1505   def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
1506                [(store (add (loadi32 addr:$dst), 1), addr:$dst),
1507                 (implicit EFLAGS)]>,
1508                Requires<[In32BitMode]>;
1509 } // Constraints = "", CodeSize = 2
1510
1511 let CodeSize = 2 in
1512 def DEC8r  : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
1513                "dec{b}\t$dst",
1514                [(set GR8:$dst, EFLAGS, (X86dec_flag GR8:$src1))]>;
1515 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {   // Can xform into LEA.
1516 def DEC16r : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
1517                "dec{w}\t$dst",
1518                [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src1))]>,
1519              OpSize, Requires<[In32BitMode]>;
1520 def DEC32r : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
1521                "dec{l}\t$dst",
1522                [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src1))]>,
1523              Requires<[In32BitMode]>;
1524 } // CodeSize = 2
1525
1526 let Constraints = "", CodeSize = 2 in {
1527   def DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
1528                [(store (add (loadi8 addr:$dst), -1), addr:$dst),
1529                 (implicit EFLAGS)]>;
1530   def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
1531                [(store (add (loadi16 addr:$dst), -1), addr:$dst),
1532                 (implicit EFLAGS)]>,
1533                OpSize, Requires<[In32BitMode]>;
1534   def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
1535                [(store (add (loadi32 addr:$dst), -1), addr:$dst),
1536                 (implicit EFLAGS)]>,
1537                Requires<[In32BitMode]>;
1538 } // Constraints = "", CodeSize = 2
1539 } // Defs = [EFLAGS]
1540
1541 // Logical operators...
1542 let Defs = [EFLAGS] in {
1543 let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
1544 def AND8rr  : I<0x20, MRMDestReg,
1545                (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1546                "and{b}\t{$src2, $dst|$dst, $src2}",
1547                [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1, GR8:$src2))]>;
1548 def AND16rr : I<0x21, MRMDestReg,
1549                 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1550                 "and{w}\t{$src2, $dst|$dst, $src2}",
1551                 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1552                                                       GR16:$src2))]>, OpSize;
1553 def AND32rr : I<0x21, MRMDestReg, 
1554                 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1555                 "and{l}\t{$src2, $dst|$dst, $src2}",
1556                 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1557                                                       GR32:$src2))]>;
1558 }
1559
1560 // AND instructions with the destination register in REG and the source register
1561 //   in R/M.  Included for the disassembler.
1562 let isCodeGenOnly = 1 in {
1563 def AND8rr_REV : I<0x22, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1564                   "and{b}\t{$src2, $dst|$dst, $src2}", []>;
1565 def AND16rr_REV : I<0x23, MRMSrcReg, (outs GR16:$dst), 
1566                     (ins GR16:$src1, GR16:$src2),
1567                    "and{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1568 def AND32rr_REV : I<0x23, MRMSrcReg, (outs GR32:$dst), 
1569                     (ins GR32:$src1, GR32:$src2),
1570                    "and{l}\t{$src2, $dst|$dst, $src2}", []>;
1571 }
1572
1573 def AND8rm   : I<0x22, MRMSrcMem, 
1574                  (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
1575                  "and{b}\t{$src2, $dst|$dst, $src2}",
1576                 [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1577                                                      (loadi8 addr:$src2)))]>;
1578 def AND16rm  : I<0x23, MRMSrcMem, 
1579                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1580                  "and{w}\t{$src2, $dst|$dst, $src2}",
1581                 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1582                                                       (loadi16 addr:$src2)))]>,
1583                OpSize;
1584 def AND32rm  : I<0x23, MRMSrcMem,
1585                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1586                  "and{l}\t{$src2, $dst|$dst, $src2}",
1587                 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1588                                                       (loadi32 addr:$src2)))]>;
1589
1590 def AND8ri   : Ii8<0x80, MRM4r, 
1591                    (outs GR8 :$dst), (ins GR8 :$src1, i8imm :$src2),
1592                    "and{b}\t{$src2, $dst|$dst, $src2}",
1593                    [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1594                                                         imm:$src2))]>;
1595 def AND16ri  : Ii16<0x81, MRM4r, 
1596                     (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
1597                     "and{w}\t{$src2, $dst|$dst, $src2}",
1598                     [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1599                                                           imm:$src2))]>, OpSize;
1600 def AND32ri  : Ii32<0x81, MRM4r, 
1601                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
1602                     "and{l}\t{$src2, $dst|$dst, $src2}",
1603                     [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1604                                                           imm:$src2))]>;
1605 def AND16ri8 : Ii8<0x83, MRM4r, 
1606                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1607                    "and{w}\t{$src2, $dst|$dst, $src2}",
1608                    [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1609                                                          i16immSExt8:$src2))]>,
1610                    OpSize;
1611 def AND32ri8 : Ii8<0x83, MRM4r, 
1612                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1613                    "and{l}\t{$src2, $dst|$dst, $src2}",
1614                    [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1615                                                          i32immSExt8:$src2))]>;
1616
1617 let Constraints = "" in {
1618   def AND8mr   : I<0x20, MRMDestMem,
1619                    (outs), (ins i8mem :$dst, GR8 :$src),
1620                    "and{b}\t{$src, $dst|$dst, $src}",
1621                    [(store (and (load addr:$dst), GR8:$src), addr:$dst),
1622                     (implicit EFLAGS)]>;
1623   def AND16mr  : I<0x21, MRMDestMem,
1624                    (outs), (ins i16mem:$dst, GR16:$src),
1625                    "and{w}\t{$src, $dst|$dst, $src}",
1626                    [(store (and (load addr:$dst), GR16:$src), addr:$dst),
1627                     (implicit EFLAGS)]>,
1628                    OpSize;
1629   def AND32mr  : I<0x21, MRMDestMem,
1630                    (outs), (ins i32mem:$dst, GR32:$src),
1631                    "and{l}\t{$src, $dst|$dst, $src}",
1632                    [(store (and (load addr:$dst), GR32:$src), addr:$dst),
1633                     (implicit EFLAGS)]>;
1634   def AND8mi   : Ii8<0x80, MRM4m,
1635                      (outs), (ins i8mem :$dst, i8imm :$src),
1636                      "and{b}\t{$src, $dst|$dst, $src}",
1637                       [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst),
1638                        (implicit EFLAGS)]>;
1639   def AND16mi  : Ii16<0x81, MRM4m,
1640                       (outs), (ins i16mem:$dst, i16imm:$src),
1641                       "and{w}\t{$src, $dst|$dst, $src}",
1642                       [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst),
1643                        (implicit EFLAGS)]>,
1644                       OpSize;
1645   def AND32mi  : Ii32<0x81, MRM4m,
1646                       (outs), (ins i32mem:$dst, i32imm:$src),
1647                       "and{l}\t{$src, $dst|$dst, $src}",
1648                       [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst),
1649                        (implicit EFLAGS)]>;
1650   def AND16mi8 : Ii8<0x83, MRM4m,
1651                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1652                      "and{w}\t{$src, $dst|$dst, $src}",
1653                 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst),
1654                  (implicit EFLAGS)]>,
1655                      OpSize;
1656   def AND32mi8 : Ii8<0x83, MRM4m,
1657                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1658                      "and{l}\t{$src, $dst|$dst, $src}",
1659                 [(store (and (load addr:$dst), i32immSExt8:$src), addr:$dst),
1660                  (implicit EFLAGS)]>;
1661
1662   def AND8i8 : Ii8<0x24, RawFrm, (outs), (ins i8imm:$src),
1663                    "and{b}\t{$src, %al|%al, $src}", []>;
1664   def AND16i16 : Ii16<0x25, RawFrm, (outs), (ins i16imm:$src),
1665                       "and{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1666   def AND32i32 : Ii32<0x25, RawFrm, (outs), (ins i32imm:$src),
1667                       "and{l}\t{$src, %eax|%eax, $src}", []>;
1668
1669 } // Constraints = ""
1670
1671
1672 let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
1673 def OR8rr    : I<0x08, MRMDestReg, (outs GR8 :$dst), 
1674                  (ins GR8 :$src1, GR8 :$src2),
1675                  "or{b}\t{$src2, $dst|$dst, $src2}",
1676                  [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1, GR8:$src2))]>;
1677 def OR16rr   : I<0x09, MRMDestReg, (outs GR16:$dst), 
1678                  (ins GR16:$src1, GR16:$src2),
1679                  "or{w}\t{$src2, $dst|$dst, $src2}",
1680                  [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,GR16:$src2))]>,
1681                OpSize;
1682 def OR32rr   : I<0x09, MRMDestReg, (outs GR32:$dst), 
1683                  (ins GR32:$src1, GR32:$src2),
1684                  "or{l}\t{$src2, $dst|$dst, $src2}",
1685                  [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,GR32:$src2))]>;
1686 }
1687
1688 // OR instructions with the destination register in REG and the source register
1689 //   in R/M.  Included for the disassembler.
1690 let isCodeGenOnly = 1 in {
1691 def OR8rr_REV : I<0x0A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1692                   "or{b}\t{$src2, $dst|$dst, $src2}", []>;
1693 def OR16rr_REV : I<0x0B, MRMSrcReg, (outs GR16:$dst),
1694                    (ins GR16:$src1, GR16:$src2),
1695                    "or{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1696 def OR32rr_REV : I<0x0B, MRMSrcReg, (outs GR32:$dst), 
1697                    (ins GR32:$src1, GR32:$src2),
1698                    "or{l}\t{$src2, $dst|$dst, $src2}", []>;
1699 }
1700                   
1701 def OR8rm    : I<0x0A, MRMSrcMem, (outs GR8 :$dst), 
1702                  (ins GR8 :$src1, i8mem :$src2),
1703                  "or{b}\t{$src2, $dst|$dst, $src2}",
1704                 [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1,
1705                                                     (load addr:$src2)))]>;
1706 def OR16rm   : I<0x0B, MRMSrcMem, (outs GR16:$dst), 
1707                  (ins GR16:$src1, i16mem:$src2),
1708                  "or{w}\t{$src2, $dst|$dst, $src2}",
1709                 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1710                                                      (load addr:$src2)))]>,
1711                OpSize;
1712 def OR32rm   : I<0x0B, MRMSrcMem, (outs GR32:$dst), 
1713                  (ins GR32:$src1, i32mem:$src2),
1714                  "or{l}\t{$src2, $dst|$dst, $src2}",
1715                 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1716                                                      (load addr:$src2)))]>;
1717
1718 def OR8ri    : Ii8 <0x80, MRM1r, (outs GR8 :$dst), 
1719                     (ins GR8 :$src1, i8imm:$src2),
1720                     "or{b}\t{$src2, $dst|$dst, $src2}",
1721                     [(set GR8:$dst,EFLAGS, (X86or_flag GR8:$src1, imm:$src2))]>;
1722 def OR16ri   : Ii16<0x81, MRM1r, (outs GR16:$dst), 
1723                     (ins GR16:$src1, i16imm:$src2),
1724                     "or{w}\t{$src2, $dst|$dst, $src2}", 
1725                     [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1726                                                         imm:$src2))]>, OpSize;
1727 def OR32ri   : Ii32<0x81, MRM1r, (outs GR32:$dst), 
1728                     (ins GR32:$src1, i32imm:$src2),
1729                     "or{l}\t{$src2, $dst|$dst, $src2}",
1730                     [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1731                                                          imm:$src2))]>;
1732
1733 def OR16ri8  : Ii8<0x83, MRM1r, (outs GR16:$dst), 
1734                    (ins GR16:$src1, i16i8imm:$src2),
1735                    "or{w}\t{$src2, $dst|$dst, $src2}",
1736                    [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1737                                                 i16immSExt8:$src2))]>, OpSize;
1738 def OR32ri8  : Ii8<0x83, MRM1r, (outs GR32:$dst), 
1739                    (ins GR32:$src1, i32i8imm:$src2),
1740                    "or{l}\t{$src2, $dst|$dst, $src2}",
1741                    [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1742                                                         i32immSExt8:$src2))]>;
1743 let Constraints = "" in {
1744   def OR8mr  : I<0x08, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
1745                  "or{b}\t{$src, $dst|$dst, $src}",
1746                  [(store (or (load addr:$dst), GR8:$src), addr:$dst),
1747                   (implicit EFLAGS)]>;
1748   def OR16mr : I<0x09, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
1749                  "or{w}\t{$src, $dst|$dst, $src}",
1750                  [(store (or (load addr:$dst), GR16:$src), addr:$dst),
1751                   (implicit EFLAGS)]>, OpSize;
1752   def OR32mr : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1753                  "or{l}\t{$src, $dst|$dst, $src}",
1754                  [(store (or (load addr:$dst), GR32:$src), addr:$dst),
1755                   (implicit EFLAGS)]>;
1756   def OR8mi    : Ii8<0x80, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
1757                  "or{b}\t{$src, $dst|$dst, $src}",
1758                  [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst),
1759                   (implicit EFLAGS)]>;
1760   def OR16mi   : Ii16<0x81, MRM1m, (outs), (ins i16mem:$dst, i16imm:$src),
1761                  "or{w}\t{$src, $dst|$dst, $src}",
1762                  [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst),
1763                   (implicit EFLAGS)]>,
1764                  OpSize;
1765   def OR32mi   : Ii32<0x81, MRM1m, (outs), (ins i32mem:$dst, i32imm:$src),
1766                  "or{l}\t{$src, $dst|$dst, $src}",
1767                  [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst),
1768                   (implicit EFLAGS)]>;
1769   def OR16mi8  : Ii8<0x83, MRM1m, (outs), (ins i16mem:$dst, i16i8imm:$src),
1770                  "or{w}\t{$src, $dst|$dst, $src}",
1771                  [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst),
1772                   (implicit EFLAGS)]>,
1773                      OpSize;
1774   def OR32mi8  : Ii8<0x83, MRM1m, (outs), (ins i32mem:$dst, i32i8imm:$src),
1775                  "or{l}\t{$src, $dst|$dst, $src}",
1776                  [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst),
1777                   (implicit EFLAGS)]>;
1778                   
1779   def OR8i8 : Ii8 <0x0C, RawFrm, (outs), (ins i8imm:$src),
1780                    "or{b}\t{$src, %al|%al, $src}", []>;
1781   def OR16i16 : Ii16 <0x0D, RawFrm, (outs), (ins i16imm:$src),
1782                       "or{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1783   def OR32i32 : Ii32 <0x0D, RawFrm, (outs), (ins i32imm:$src),
1784                       "or{l}\t{$src, %eax|%eax, $src}", []>;
1785 } // Constraints = ""
1786
1787
1788 let isCommutable = 1 in { // X = XOR Y, Z --> X = XOR Z, Y
1789   def XOR8rr   : I<0x30, MRMDestReg,
1790                    (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1791                    "xor{b}\t{$src2, $dst|$dst, $src2}",
1792                    [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
1793                                                         GR8:$src2))]>;
1794   def XOR16rr  : I<0x31, MRMDestReg, 
1795                    (outs GR16:$dst), (ins GR16:$src1, GR16:$src2), 
1796                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1797                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
1798                                                          GR16:$src2))]>, OpSize;
1799   def XOR32rr  : I<0x31, MRMDestReg, 
1800                    (outs GR32:$dst), (ins GR32:$src1, GR32:$src2), 
1801                    "xor{l}\t{$src2, $dst|$dst, $src2}",
1802                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
1803                                                          GR32:$src2))]>;
1804 } // isCommutable = 1
1805
1806 // XOR instructions with the destination register in REG and the source register
1807 //   in R/M.  Included for the disassembler.
1808 let isCodeGenOnly = 1 in {
1809 def XOR8rr_REV : I<0x32, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1810                   "xor{b}\t{$src2, $dst|$dst, $src2}", []>;
1811 def XOR16rr_REV : I<0x33, MRMSrcReg, (outs GR16:$dst), 
1812                     (ins GR16:$src1, GR16:$src2),
1813                    "xor{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1814 def XOR32rr_REV : I<0x33, MRMSrcReg, (outs GR32:$dst), 
1815                     (ins GR32:$src1, GR32:$src2),
1816                    "xor{l}\t{$src2, $dst|$dst, $src2}", []>;
1817 }
1818
1819 def XOR8rm   : I<0x32, MRMSrcMem, 
1820                  (outs GR8 :$dst), (ins GR8:$src1, i8mem :$src2), 
1821                  "xor{b}\t{$src2, $dst|$dst, $src2}",
1822                  [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
1823                                                       (load addr:$src2)))]>;
1824 def XOR16rm  : I<0x33, MRMSrcMem, 
1825                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2), 
1826                  "xor{w}\t{$src2, $dst|$dst, $src2}",
1827                  [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
1828                                                        (load addr:$src2)))]>,
1829                  OpSize;
1830 def XOR32rm  : I<0x33, MRMSrcMem, 
1831                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2), 
1832                  "xor{l}\t{$src2, $dst|$dst, $src2}",
1833                  [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
1834                                                        (load addr:$src2)))]>;
1835
1836 def XOR8ri  : Ii8<0x80, MRM6r, 
1837                   (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2), 
1838                   "xor{b}\t{$src2, $dst|$dst, $src2}",
1839                   [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1, imm:$src2))]>;
1840 def XOR16ri : Ii16<0x81, MRM6r, 
1841                    (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2), 
1842                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1843                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
1844                                                          imm:$src2))]>, OpSize;
1845 def XOR32ri  : Ii32<0x81, MRM6r, 
1846                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2), 
1847                     "xor{l}\t{$src2, $dst|$dst, $src2}",
1848                     [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
1849                                                           imm:$src2))]>;
1850 def XOR16ri8 : Ii8<0x83, MRM6r, 
1851                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1852                    "xor{w}\t{$src2, $dst|$dst, $src2}",
1853                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
1854                                                          i16immSExt8:$src2))]>,
1855                    OpSize;
1856 def XOR32ri8 : Ii8<0x83, MRM6r, 
1857                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1858                    "xor{l}\t{$src2, $dst|$dst, $src2}",
1859                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
1860                                                          i32immSExt8:$src2))]>;
1861
1862 let Constraints = "" in {
1863   def XOR8mr   : I<0x30, MRMDestMem,
1864                    (outs), (ins i8mem :$dst, GR8 :$src),
1865                    "xor{b}\t{$src, $dst|$dst, $src}",
1866                    [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
1867                     (implicit EFLAGS)]>;
1868   def XOR16mr  : I<0x31, MRMDestMem,
1869                    (outs), (ins i16mem:$dst, GR16:$src),
1870                    "xor{w}\t{$src, $dst|$dst, $src}",
1871                    [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
1872                     (implicit EFLAGS)]>,
1873                    OpSize;
1874   def XOR32mr  : I<0x31, MRMDestMem,
1875                    (outs), (ins i32mem:$dst, GR32:$src),
1876                    "xor{l}\t{$src, $dst|$dst, $src}",
1877                    [(store (xor (load addr:$dst), GR32:$src), addr:$dst),
1878                     (implicit EFLAGS)]>;
1879   def XOR8mi   : Ii8<0x80, MRM6m,
1880                      (outs), (ins i8mem :$dst, i8imm :$src),
1881                      "xor{b}\t{$src, $dst|$dst, $src}",
1882                     [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst),
1883                      (implicit EFLAGS)]>;
1884   def XOR16mi  : Ii16<0x81, MRM6m,
1885                       (outs), (ins i16mem:$dst, i16imm:$src),
1886                       "xor{w}\t{$src, $dst|$dst, $src}",
1887                    [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst),
1888                     (implicit EFLAGS)]>,
1889                       OpSize;
1890   def XOR32mi  : Ii32<0x81, MRM6m,
1891                       (outs), (ins i32mem:$dst, i32imm:$src),
1892                       "xor{l}\t{$src, $dst|$dst, $src}",
1893                    [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst),
1894                     (implicit EFLAGS)]>;
1895   def XOR16mi8 : Ii8<0x83, MRM6m,
1896                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1897                      "xor{w}\t{$src, $dst|$dst, $src}",
1898                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst),
1899                   (implicit EFLAGS)]>,
1900                      OpSize;
1901   def XOR32mi8 : Ii8<0x83, MRM6m,
1902                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1903                      "xor{l}\t{$src, $dst|$dst, $src}",
1904                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst),
1905                   (implicit EFLAGS)]>;
1906                   
1907   def XOR8i8   : Ii8 <0x34, RawFrm, (outs), (ins i8imm:$src),
1908                       "xor{b}\t{$src, %al|%al, $src}", []>;
1909   def XOR16i16 : Ii16<0x35, RawFrm, (outs), (ins i16imm:$src),
1910                       "xor{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1911   def XOR32i32 : Ii32<0x35, RawFrm, (outs), (ins i32imm:$src),
1912                       "xor{l}\t{$src, %eax|%eax, $src}", []>;
1913 } // Constraints = ""
1914 } // Defs = [EFLAGS]
1915
1916 // Shift instructions
1917 let Defs = [EFLAGS] in {
1918 let Uses = [CL] in {
1919 def SHL8rCL  : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1),
1920                  "shl{b}\t{%cl, $dst|$dst, CL}",
1921                  [(set GR8:$dst, (shl GR8:$src1, CL))]>;
1922 def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
1923                  "shl{w}\t{%cl, $dst|$dst, CL}",
1924                  [(set GR16:$dst, (shl GR16:$src1, CL))]>, OpSize;
1925 def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
1926                  "shl{l}\t{%cl, $dst|$dst, CL}",
1927                  [(set GR32:$dst, (shl GR32:$src1, CL))]>;
1928 } // Uses = [CL]
1929
1930 def SHL8ri   : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
1931                    "shl{b}\t{$src2, $dst|$dst, $src2}",
1932                    [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))]>;
1933                    
1934 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
1935 def SHL16ri  : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
1936                    "shl{w}\t{$src2, $dst|$dst, $src2}",
1937                    [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
1938 def SHL32ri  : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
1939                    "shl{l}\t{$src2, $dst|$dst, $src2}",
1940                    [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))]>;
1941
1942 // NOTE: We don't include patterns for shifts of a register by one, because
1943 // 'add reg,reg' is cheaper.
1944
1945 def SHL8r1   : I<0xD0, MRM4r, (outs GR8:$dst), (ins GR8:$src1),
1946                  "shl{b}\t$dst", []>;
1947 def SHL16r1  : I<0xD1, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
1948                  "shl{w}\t$dst", []>, OpSize;
1949 def SHL32r1  : I<0xD1, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
1950                  "shl{l}\t$dst", []>;
1951
1952 } // isConvertibleToThreeAddress = 1
1953
1954 let Constraints = "" in {
1955   let Uses = [CL] in {
1956   def SHL8mCL  : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
1957                    "shl{b}\t{%cl, $dst|$dst, CL}",
1958                    [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
1959   def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
1960                    "shl{w}\t{%cl, $dst|$dst, CL}",
1961                    [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
1962   def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
1963                    "shl{l}\t{%cl, $dst|$dst, CL}",
1964                    [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>;
1965   }
1966   def SHL8mi   : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
1967                      "shl{b}\t{$src, $dst|$dst, $src}",
1968                   [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1969   def SHL16mi  : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
1970                      "shl{w}\t{$src, $dst|$dst, $src}",
1971                  [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
1972                      OpSize;
1973   def SHL32mi  : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
1974                      "shl{l}\t{$src, $dst|$dst, $src}",
1975                  [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
1976
1977   // Shift by 1
1978   def SHL8m1   : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
1979                    "shl{b}\t$dst",
1980                   [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
1981   def SHL16m1  : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
1982                    "shl{w}\t$dst",
1983                  [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
1984                      OpSize;
1985   def SHL32m1  : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
1986                    "shl{l}\t$dst",
1987                  [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
1988 } // Constraints = ""
1989
1990 let Uses = [CL] in {
1991 def SHR8rCL  : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src1),
1992                  "shr{b}\t{%cl, $dst|$dst, CL}",
1993                  [(set GR8:$dst, (srl GR8:$src1, CL))]>;
1994 def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
1995                  "shr{w}\t{%cl, $dst|$dst, CL}",
1996                  [(set GR16:$dst, (srl GR16:$src1, CL))]>, OpSize;
1997 def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
1998                  "shr{l}\t{%cl, $dst|$dst, CL}",
1999                  [(set GR32:$dst, (srl GR32:$src1, CL))]>;
2000 }
2001
2002 def SHR8ri   : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2003                    "shr{b}\t{$src2, $dst|$dst, $src2}",
2004                    [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))]>;
2005 def SHR16ri  : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2006                    "shr{w}\t{$src2, $dst|$dst, $src2}",
2007                    [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
2008 def SHR32ri  : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2009                    "shr{l}\t{$src2, $dst|$dst, $src2}",
2010                    [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))]>;
2011
2012 // Shift by 1
2013 def SHR8r1   : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
2014                  "shr{b}\t$dst",
2015                  [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
2016 def SHR16r1  : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
2017                  "shr{w}\t$dst",
2018                  [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize;
2019 def SHR32r1  : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
2020                  "shr{l}\t$dst",
2021                  [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>;
2022
2023 let Constraints = "" in {
2024   let Uses = [CL] in {
2025   def SHR8mCL  : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
2026                    "shr{b}\t{%cl, $dst|$dst, CL}",
2027                    [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
2028   def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
2029                    "shr{w}\t{%cl, $dst|$dst, CL}",
2030                    [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
2031                    OpSize;
2032   def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
2033                    "shr{l}\t{%cl, $dst|$dst, CL}",
2034                    [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>;
2035   }
2036   def SHR8mi   : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
2037                      "shr{b}\t{$src, $dst|$dst, $src}",
2038                   [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2039   def SHR16mi  : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
2040                      "shr{w}\t{$src, $dst|$dst, $src}",
2041                  [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2042                      OpSize;
2043   def SHR32mi  : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
2044                      "shr{l}\t{$src, $dst|$dst, $src}",
2045                  [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2046
2047   // Shift by 1
2048   def SHR8m1   : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
2049                    "shr{b}\t$dst",
2050                   [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2051   def SHR16m1  : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
2052                    "shr{w}\t$dst",
2053                  [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,OpSize;
2054   def SHR32m1  : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
2055                    "shr{l}\t$dst",
2056                  [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2057 } // Constraints = ""
2058
2059 let Uses = [CL] in {
2060 def SAR8rCL  : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
2061                  "sar{b}\t{%cl, $dst|$dst, CL}",
2062                  [(set GR8:$dst, (sra GR8:$src1, CL))]>;
2063 def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
2064                  "sar{w}\t{%cl, $dst|$dst, CL}",
2065                  [(set GR16:$dst, (sra GR16:$src1, CL))]>, OpSize;
2066 def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
2067                  "sar{l}\t{%cl, $dst|$dst, CL}",
2068                  [(set GR32:$dst, (sra GR32:$src1, CL))]>;
2069 }
2070
2071 def SAR8ri   : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2072                    "sar{b}\t{$src2, $dst|$dst, $src2}",
2073                    [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
2074 def SAR16ri  : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2075                    "sar{w}\t{$src2, $dst|$dst, $src2}",
2076                    [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
2077                    OpSize;
2078 def SAR32ri  : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2079                    "sar{l}\t{$src2, $dst|$dst, $src2}",
2080                    [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>;
2081
2082 // Shift by 1
2083 def SAR8r1   : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
2084                  "sar{b}\t$dst",
2085                  [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
2086 def SAR16r1  : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
2087                  "sar{w}\t$dst",
2088                  [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize;
2089 def SAR32r1  : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
2090                  "sar{l}\t$dst",
2091                  [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>;
2092
2093 let Constraints = "" in {
2094   let Uses = [CL] in {
2095   def SAR8mCL  : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
2096                    "sar{b}\t{%cl, $dst|$dst, CL}",
2097                    [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>;
2098   def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
2099                    "sar{w}\t{%cl, $dst|$dst, CL}",
2100                    [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2101   def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst), 
2102                    "sar{l}\t{%cl, $dst|$dst, CL}",
2103                    [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>;
2104   }
2105   def SAR8mi   : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
2106                      "sar{b}\t{$src, $dst|$dst, $src}",
2107                   [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2108   def SAR16mi  : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
2109                      "sar{w}\t{$src, $dst|$dst, $src}",
2110                  [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2111                      OpSize;
2112   def SAR32mi  : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
2113                      "sar{l}\t{$src, $dst|$dst, $src}",
2114                  [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2115
2116   // Shift by 1
2117   def SAR8m1   : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
2118                    "sar{b}\t$dst",
2119                   [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2120   def SAR16m1  : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
2121                    "sar{w}\t$dst",
2122                  [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2123                      OpSize;
2124   def SAR32m1  : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
2125                    "sar{l}\t$dst",
2126                  [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2127 } // Constraints = ""
2128
2129 // Rotate instructions
2130
2131 def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
2132                "rcl{b}\t{1, $dst|$dst, 1}", []>;
2133 let Uses = [CL] in {
2134 def RCL8rCL : I<0xD2, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
2135                 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
2136 }
2137 def RCL8ri : Ii8<0xC0, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
2138                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2139   
2140 def RCL16r1 : I<0xD1, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
2141                 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2142 let Uses = [CL] in {
2143 def RCL16rCL : I<0xD3, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
2144                  "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2145 }
2146 def RCL16ri : Ii8<0xC1, MRM2r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
2147                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2148
2149 def RCL32r1 : I<0xD1, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
2150                 "rcl{l}\t{1, $dst|$dst, 1}", []>;
2151 let Uses = [CL] in {
2152 def RCL32rCL : I<0xD3, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
2153                  "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
2154 }
2155 def RCL32ri : Ii8<0xC1, MRM2r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
2156                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2157                   
2158 def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
2159                "rcr{b}\t{1, $dst|$dst, 1}", []>;
2160 let Uses = [CL] in {
2161 def RCR8rCL : I<0xD2, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
2162                 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
2163 }
2164 def RCR8ri : Ii8<0xC0, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
2165                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2166   
2167 def RCR16r1 : I<0xD1, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
2168                 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2169 let Uses = [CL] in {
2170 def RCR16rCL : I<0xD3, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
2171                  "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2172 }
2173 def RCR16ri : Ii8<0xC1, MRM3r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
2174                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2175
2176 def RCR32r1 : I<0xD1, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
2177                 "rcr{l}\t{1, $dst|$dst, 1}", []>;
2178 let Uses = [CL] in {
2179 def RCR32rCL : I<0xD3, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
2180                  "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
2181 }
2182 def RCR32ri : Ii8<0xC1, MRM3r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
2183                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2184
2185 let Constraints = "" in {
2186 def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$dst),
2187                "rcl{b}\t{1, $dst|$dst, 1}", []>;
2188 def RCL8mi : Ii8<0xC0, MRM2m, (outs), (ins i8mem:$dst, i8imm:$cnt),
2189                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2190 def RCL16m1 : I<0xD1, MRM2m, (outs), (ins i16mem:$dst),
2191                 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2192 def RCL16mi : Ii8<0xC1, MRM2m, (outs), (ins i16mem:$dst, i8imm:$cnt),
2193                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2194 def RCL32m1 : I<0xD1, MRM2m, (outs), (ins i32mem:$dst),
2195                 "rcl{l}\t{1, $dst|$dst, 1}", []>;
2196 def RCL32mi : Ii8<0xC1, MRM2m, (outs), (ins i32mem:$dst, i8imm:$cnt),
2197                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2198 def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$dst),
2199                "rcr{b}\t{1, $dst|$dst, 1}", []>;
2200 def RCR8mi : Ii8<0xC0, MRM3m, (outs), (ins i8mem:$dst, i8imm:$cnt),
2201                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2202 def RCR16m1 : I<0xD1, MRM3m, (outs), (ins i16mem:$dst),
2203                 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2204 def RCR16mi : Ii8<0xC1, MRM3m, (outs), (ins i16mem:$dst, i8imm:$cnt),
2205                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2206 def RCR32m1 : I<0xD1, MRM3m, (outs), (ins i32mem:$dst),
2207                 "rcr{l}\t{1, $dst|$dst, 1}", []>;
2208 def RCR32mi : Ii8<0xC1, MRM3m, (outs), (ins i32mem:$dst, i8imm:$cnt),
2209                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2210
2211 let Uses = [CL] in {
2212 def RCL8mCL : I<0xD2, MRM2m, (outs), (ins i8mem:$dst),
2213                 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
2214 def RCL16mCL : I<0xD3, MRM2m, (outs), (ins i16mem:$dst),
2215                  "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2216 def RCL32mCL : I<0xD3, MRM2m, (outs), (ins i32mem:$dst),
2217                  "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
2218 def RCR8mCL : I<0xD2, MRM3m, (outs), (ins i8mem:$dst),
2219                 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
2220 def RCR16mCL : I<0xD3, MRM3m, (outs), (ins i16mem:$dst),
2221                  "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2222 def RCR32mCL : I<0xD3, MRM3m, (outs), (ins i32mem:$dst),
2223                  "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
2224 }
2225 } // Constraints = ""
2226
2227 // FIXME: provide shorter instructions when imm8 == 1
2228 let Uses = [CL] in {
2229 def ROL8rCL  : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
2230                  "rol{b}\t{%cl, $dst|$dst, CL}",
2231                  [(set GR8:$dst, (rotl GR8:$src1, CL))]>;
2232 def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
2233                  "rol{w}\t{%cl, $dst|$dst, CL}",
2234                  [(set GR16:$dst, (rotl GR16:$src1, CL))]>, OpSize;
2235 def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
2236                  "rol{l}\t{%cl, $dst|$dst, CL}",
2237                  [(set GR32:$dst, (rotl GR32:$src1, CL))]>;
2238 }
2239
2240 def ROL8ri   : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2241                    "rol{b}\t{$src2, $dst|$dst, $src2}",
2242                    [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
2243 def ROL16ri  : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2244                    "rol{w}\t{$src2, $dst|$dst, $src2}",
2245                    [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>, 
2246                    OpSize;
2247 def ROL32ri  : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2248                    "rol{l}\t{$src2, $dst|$dst, $src2}",
2249                    [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>;
2250
2251 // Rotate by 1
2252 def ROL8r1   : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
2253                  "rol{b}\t$dst",
2254                  [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
2255 def ROL16r1  : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
2256                  "rol{w}\t$dst",
2257                  [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize;
2258 def ROL32r1  : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
2259                  "rol{l}\t$dst",
2260                  [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>;
2261
2262 let Constraints = "" in {
2263   let Uses = [CL] in {
2264   def ROL8mCL  : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
2265                    "rol{b}\t{%cl, $dst|$dst, CL}",
2266                    [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
2267   def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
2268                    "rol{w}\t{%cl, $dst|$dst, CL}",
2269                    [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2270   def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
2271                    "rol{l}\t{%cl, $dst|$dst, CL}",
2272                    [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>;
2273   }
2274   def ROL8mi   : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src),
2275                      "rol{b}\t{$src, $dst|$dst, $src}",
2276                  [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2277   def ROL16mi  : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src),
2278                      "rol{w}\t{$src, $dst|$dst, $src}",
2279                 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2280                      OpSize;
2281   def ROL32mi  : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src),
2282                      "rol{l}\t{$src, $dst|$dst, $src}",
2283                 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2284
2285   // Rotate by 1
2286   def ROL8m1   : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
2287                    "rol{b}\t$dst",
2288                  [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2289   def ROL16m1  : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
2290                    "rol{w}\t$dst",
2291                 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2292                      OpSize;
2293   def ROL32m1  : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
2294                    "rol{l}\t$dst",
2295                 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2296 } // Constraints = ""
2297
2298 let Uses = [CL] in {
2299 def ROR8rCL  : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
2300                  "ror{b}\t{%cl, $dst|$dst, CL}",
2301                  [(set GR8:$dst, (rotr GR8:$src1, CL))]>;
2302 def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
2303                  "ror{w}\t{%cl, $dst|$dst, CL}",
2304                  [(set GR16:$dst, (rotr GR16:$src1, CL))]>, OpSize;
2305 def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
2306                  "ror{l}\t{%cl, $dst|$dst, CL}",
2307                  [(set GR32:$dst, (rotr GR32:$src1, CL))]>;
2308 }
2309
2310 def ROR8ri   : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2311                    "ror{b}\t{$src2, $dst|$dst, $src2}",
2312                    [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))]>;
2313 def ROR16ri  : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2314                    "ror{w}\t{$src2, $dst|$dst, $src2}",
2315                    [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))]>, 
2316                    OpSize;
2317 def ROR32ri  : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2318                    "ror{l}\t{$src2, $dst|$dst, $src2}",
2319                    [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))]>;
2320
2321 // Rotate by 1
2322 def ROR8r1   : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
2323                  "ror{b}\t$dst",
2324                  [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))]>;
2325 def ROR16r1  : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
2326                  "ror{w}\t$dst",
2327                  [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))]>, OpSize;
2328 def ROR32r1  : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
2329                  "ror{l}\t$dst",
2330                  [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))]>;
2331
2332 let Constraints = "" in {
2333   let Uses = [CL] in {
2334   def ROR8mCL  : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
2335                    "ror{b}\t{%cl, $dst|$dst, CL}",
2336                    [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
2337   def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
2338                    "ror{w}\t{%cl, $dst|$dst, CL}",
2339                    [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2340   def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst), 
2341                    "ror{l}\t{%cl, $dst|$dst, CL}",
2342                    [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>;
2343   }
2344   def ROR8mi   : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
2345                      "ror{b}\t{$src, $dst|$dst, $src}",
2346                  [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2347   def ROR16mi  : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
2348                      "ror{w}\t{$src, $dst|$dst, $src}",
2349                 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2350                      OpSize;
2351   def ROR32mi  : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
2352                      "ror{l}\t{$src, $dst|$dst, $src}",
2353                 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2354
2355   // Rotate by 1
2356   def ROR8m1   : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
2357                    "ror{b}\t$dst",
2358                  [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2359   def ROR16m1  : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
2360                    "ror{w}\t$dst",
2361                 [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2362                      OpSize;
2363   def ROR32m1  : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
2364                    "ror{l}\t$dst",
2365                 [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2366 } // Constraints = ""
2367
2368
2369 // Double shift instructions (generalizations of rotate)
2370 let Uses = [CL] in {
2371 def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst), 
2372                    (ins GR32:$src1, GR32:$src2),
2373                    "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2374                    [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>, TB;
2375 def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst),
2376                    (ins GR32:$src1, GR32:$src2),
2377                    "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2378                    [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>, TB;
2379 def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst), 
2380                    (ins GR16:$src1, GR16:$src2),
2381                    "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2382                    [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
2383                    TB, OpSize;
2384 def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst), 
2385                    (ins GR16:$src1, GR16:$src2),
2386                    "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2387                    [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
2388                    TB, OpSize;
2389 }
2390
2391 let isCommutable = 1 in {  // These instructions commute to each other.
2392 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
2393                      (outs GR32:$dst), 
2394                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
2395                      "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2396                      [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
2397                                       (i8 imm:$src3)))]>,
2398                  TB;
2399 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
2400                      (outs GR32:$dst), 
2401                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
2402                      "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2403                      [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
2404                                       (i8 imm:$src3)))]>,
2405                  TB;
2406 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
2407                      (outs GR16:$dst), 
2408                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
2409                      "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2410                      [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
2411                                       (i8 imm:$src3)))]>,
2412                      TB, OpSize;
2413 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
2414                      (outs GR16:$dst), 
2415                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
2416                      "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2417                      [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
2418                                       (i8 imm:$src3)))]>,
2419                      TB, OpSize;
2420 }
2421
2422 let Constraints = "" in {
2423   let Uses = [CL] in {
2424   def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2425                      "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2426                      [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
2427                        addr:$dst)]>, TB;
2428   def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2429                     "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2430                     [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
2431                       addr:$dst)]>, TB;
2432   }
2433   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
2434                       (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
2435                       "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2436                       [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
2437                                         (i8 imm:$src3)), addr:$dst)]>,
2438                       TB;
2439   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
2440                        (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
2441                        "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2442                        [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
2443                                          (i8 imm:$src3)), addr:$dst)]>,
2444                        TB;
2445
2446   let Uses = [CL] in {
2447   def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2448                      "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2449                      [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
2450                        addr:$dst)]>, TB, OpSize;
2451   def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2452                     "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2453                     [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
2454                       addr:$dst)]>, TB, OpSize;
2455   }
2456   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
2457                       (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
2458                       "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2459                       [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
2460                                         (i8 imm:$src3)), addr:$dst)]>,
2461                       TB, OpSize;
2462   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
2463                        (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
2464                        "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2465                       [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
2466                                         (i8 imm:$src3)), addr:$dst)]>,
2467                        TB, OpSize;
2468 } // Constraints = ""
2469 } // Defs = [EFLAGS]
2470
2471
2472 // Arithmetic.
2473 let Defs = [EFLAGS] in {
2474 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
2475 // Register-Register Addition
2476 def ADD8rr    : I<0x00, MRMDestReg, (outs GR8 :$dst),
2477                                     (ins GR8 :$src1, GR8 :$src2),
2478                   "add{b}\t{$src2, $dst|$dst, $src2}",
2479                   [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1, GR8:$src2))]>;
2480
2481 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2482 // Register-Register Addition
2483 def ADD16rr  : I<0x01, MRMDestReg, (outs GR16:$dst),
2484                                    (ins GR16:$src1, GR16:$src2),
2485                  "add{w}\t{$src2, $dst|$dst, $src2}",
2486                  [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2487                                                        GR16:$src2))]>, OpSize;
2488 def ADD32rr  : I<0x01, MRMDestReg, (outs GR32:$dst),
2489                                    (ins GR32:$src1, GR32:$src2),
2490                  "add{l}\t{$src2, $dst|$dst, $src2}",
2491                  [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2492                                                        GR32:$src2))]>;
2493 } // end isConvertibleToThreeAddress
2494 } // end isCommutable
2495
2496 // These are alternate spellings for use by the disassembler, we mark them as
2497 // code gen only to ensure they aren't matched by the assembler.
2498 let isCodeGenOnly = 1 in {
2499   def ADD8rr_alt: I<0x02, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2500                    "add{b}\t{$src2, $dst|$dst, $src2}", []>;
2501   def ADD16rr_alt: I<0x03, MRMSrcReg,(outs GR16:$dst),(ins GR16:$src1, GR16:$src2),
2502                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2503   def ADD32rr_alt: I<0x03, MRMSrcReg,(outs GR32:$dst),(ins GR32:$src1, GR32:$src2),
2504                     "add{l}\t{$src2, $dst|$dst, $src2}", []>;
2505 }
2506
2507 // Register-Memory Addition
2508 def ADD8rm   : I<0x02, MRMSrcMem, (outs GR8 :$dst),
2509                                   (ins GR8 :$src1, i8mem :$src2),
2510                  "add{b}\t{$src2, $dst|$dst, $src2}",
2511                  [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1,
2512                                                       (load addr:$src2)))]>;
2513 def ADD16rm  : I<0x03, MRMSrcMem, (outs GR16:$dst),
2514                                   (ins GR16:$src1, i16mem:$src2),
2515                  "add{w}\t{$src2, $dst|$dst, $src2}",
2516                  [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2517                                                   (load addr:$src2)))]>, OpSize;
2518 def ADD32rm  : I<0x03, MRMSrcMem, (outs GR32:$dst),
2519                                   (ins GR32:$src1, i32mem:$src2),
2520                  "add{l}\t{$src2, $dst|$dst, $src2}",
2521                  [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2522                                                        (load addr:$src2)))]>;
2523                   
2524 // Register-Integer Addition
2525 def ADD8ri    : Ii8<0x80, MRM0r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2526                     "add{b}\t{$src2, $dst|$dst, $src2}",
2527                     [(set GR8:$dst, EFLAGS,
2528                           (X86add_flag GR8:$src1, imm:$src2))]>;
2529
2530 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2531 // Register-Integer Addition
2532 def ADD16ri  : Ii16<0x81, MRM0r, (outs GR16:$dst),
2533                                  (ins GR16:$src1, i16imm:$src2),
2534                     "add{w}\t{$src2, $dst|$dst, $src2}",
2535                     [(set GR16:$dst, EFLAGS,
2536                           (X86add_flag GR16:$src1, imm:$src2))]>, OpSize;
2537 def ADD32ri  : Ii32<0x81, MRM0r, (outs GR32:$dst),
2538                                  (ins GR32:$src1, i32imm:$src2),
2539                     "add{l}\t{$src2, $dst|$dst, $src2}",
2540                     [(set GR32:$dst, EFLAGS, 
2541                           (X86add_flag GR32:$src1, imm:$src2))]>;
2542 def ADD16ri8 : Ii8<0x83, MRM0r, (outs GR16:$dst),
2543                                 (ins GR16:$src1, i16i8imm:$src2),
2544                    "add{w}\t{$src2, $dst|$dst, $src2}",
2545                    [(set GR16:$dst, EFLAGS,
2546                          (X86add_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
2547 def ADD32ri8 : Ii8<0x83, MRM0r, (outs GR32:$dst),
2548                                 (ins GR32:$src1, i32i8imm:$src2),
2549                    "add{l}\t{$src2, $dst|$dst, $src2}",
2550                    [(set GR32:$dst, EFLAGS,
2551                          (X86add_flag GR32:$src1, i32immSExt8:$src2))]>;
2552 }
2553
2554 let Constraints = "" in {
2555   // Memory-Register Addition
2556   def ADD8mr   : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2557                    "add{b}\t{$src2, $dst|$dst, $src2}",
2558                    [(store (add (load addr:$dst), GR8:$src2), addr:$dst),
2559                     (implicit EFLAGS)]>;
2560   def ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2561                    "add{w}\t{$src2, $dst|$dst, $src2}",
2562                    [(store (add (load addr:$dst), GR16:$src2), addr:$dst),
2563                     (implicit EFLAGS)]>, OpSize;
2564   def ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2565                    "add{l}\t{$src2, $dst|$dst, $src2}",
2566                    [(store (add (load addr:$dst), GR32:$src2), addr:$dst),
2567                     (implicit EFLAGS)]>;
2568   def ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
2569                      "add{b}\t{$src2, $dst|$dst, $src2}",
2570                    [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst),
2571                     (implicit EFLAGS)]>;
2572   def ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
2573                       "add{w}\t{$src2, $dst|$dst, $src2}",
2574                   [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst),
2575                    (implicit EFLAGS)]>, OpSize;
2576   def ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
2577                       "add{l}\t{$src2, $dst|$dst, $src2}",
2578                       [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst),
2579                        (implicit EFLAGS)]>;
2580   def ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2581                      "add{w}\t{$src2, $dst|$dst, $src2}",
2582                      [(store (add (load addr:$dst), i16immSExt8:$src2),
2583                                   addr:$dst),
2584                       (implicit EFLAGS)]>, OpSize;
2585   def ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2586                      "add{l}\t{$src2, $dst|$dst, $src2}",
2587                   [(store (add (load addr:$dst), i32immSExt8:$src2),
2588                                addr:$dst),
2589                    (implicit EFLAGS)]>;
2590
2591   // addition to rAX
2592   def ADD8i8 : Ii8<0x04, RawFrm, (outs), (ins i8imm:$src),
2593                    "add{b}\t{$src, %al|%al, $src}", []>;
2594   def ADD16i16 : Ii16<0x05, RawFrm, (outs), (ins i16imm:$src),
2595                       "add{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2596   def ADD32i32 : Ii32<0x05, RawFrm, (outs), (ins i32imm:$src),
2597                       "add{l}\t{$src, %eax|%eax, $src}", []>;
2598 } // Constraints = ""
2599
2600 let Uses = [EFLAGS] in {
2601 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
2602 def ADC8rr   : I<0x10, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2603                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2604                  [(set GR8:$dst, (adde GR8:$src1, GR8:$src2))]>;
2605 def ADC16rr  : I<0x11, MRMDestReg, (outs GR16:$dst),
2606                                    (ins GR16:$src1, GR16:$src2),
2607                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2608                  [(set GR16:$dst, (adde GR16:$src1, GR16:$src2))]>, OpSize;
2609 def ADC32rr  : I<0x11, MRMDestReg, (outs GR32:$dst),
2610                                    (ins GR32:$src1, GR32:$src2),
2611                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2612                  [(set GR32:$dst, (adde GR32:$src1, GR32:$src2))]>;
2613 }
2614
2615 let isCodeGenOnly = 1 in {
2616 def ADC8rr_REV : I<0x12, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2617                  "adc{b}\t{$src2, $dst|$dst, $src2}", []>;
2618 def ADC16rr_REV : I<0x13, MRMSrcReg, (outs GR16:$dst), 
2619                     (ins GR16:$src1, GR16:$src2),
2620                     "adc{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2621 def ADC32rr_REV : I<0x13, MRMSrcReg, (outs GR32:$dst), 
2622                     (ins GR32:$src1, GR32:$src2),
2623                     "adc{l}\t{$src2, $dst|$dst, $src2}", []>;
2624 }
2625
2626 def ADC8rm   : I<0x12, MRMSrcMem , (outs GR8:$dst), 
2627                                    (ins GR8:$src1, i8mem:$src2),
2628                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2629                  [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2)))]>;
2630 def ADC16rm  : I<0x13, MRMSrcMem , (outs GR16:$dst),
2631                                    (ins GR16:$src1, i16mem:$src2),
2632                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2633                  [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2)))]>,
2634                  OpSize;
2635 def ADC32rm  : I<0x13, MRMSrcMem , (outs GR32:$dst),
2636                                    (ins GR32:$src1, i32mem:$src2),
2637                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2638                  [(set GR32:$dst, (adde GR32:$src1, (load addr:$src2)))]>;
2639 def ADC8ri   : Ii8<0x80, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2640                     "adc{b}\t{$src2, $dst|$dst, $src2}",
2641                  [(set GR8:$dst, (adde GR8:$src1, imm:$src2))]>;
2642 def ADC16ri  : Ii16<0x81, MRM2r, (outs GR16:$dst),
2643                                  (ins GR16:$src1, i16imm:$src2),
2644                     "adc{w}\t{$src2, $dst|$dst, $src2}",
2645                  [(set GR16:$dst, (adde GR16:$src1, imm:$src2))]>, OpSize;
2646 def ADC16ri8 : Ii8<0x83, MRM2r, (outs GR16:$dst),
2647                                 (ins GR16:$src1, i16i8imm:$src2),
2648                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2649                  [(set GR16:$dst, (adde GR16:$src1, i16immSExt8:$src2))]>,
2650                  OpSize;
2651 def ADC32ri  : Ii32<0x81, MRM2r, (outs GR32:$dst),
2652                                  (ins GR32:$src1, i32imm:$src2),
2653                     "adc{l}\t{$src2, $dst|$dst, $src2}",
2654                  [(set GR32:$dst, (adde GR32:$src1, imm:$src2))]>;
2655 def ADC32ri8 : Ii8<0x83, MRM2r, (outs GR32:$dst),
2656                                 (ins GR32:$src1, i32i8imm:$src2),
2657                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2658                  [(set GR32:$dst, (adde GR32:$src1, i32immSExt8:$src2))]>;
2659
2660 let Constraints = "" in {
2661   def ADC8mr   : I<0x10, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2662                    "adc{b}\t{$src2, $dst|$dst, $src2}",
2663                    [(store (adde (load addr:$dst), GR8:$src2), addr:$dst)]>;
2664   def ADC16mr  : I<0x11, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2665                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2666                    [(store (adde (load addr:$dst), GR16:$src2), addr:$dst)]>,
2667                    OpSize;
2668   def ADC32mr  : I<0x11, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2669                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2670                    [(store (adde (load addr:$dst), GR32:$src2), addr:$dst)]>;
2671   def ADC8mi   : Ii8<0x80, MRM2m, (outs), (ins i8mem:$dst, i8imm:$src2),
2672                       "adc{b}\t{$src2, $dst|$dst, $src2}",
2673                   [(store (adde (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2674   def ADC16mi  : Ii16<0x81, MRM2m, (outs), (ins i16mem:$dst, i16imm:$src2),
2675                       "adc{w}\t{$src2, $dst|$dst, $src2}",
2676                   [(store (adde (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2677                   OpSize;
2678   def ADC16mi8 : Ii8<0x83, MRM2m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2679                      "adc{w}\t{$src2, $dst|$dst, $src2}",
2680                [(store (adde (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2681                OpSize;
2682   def ADC32mi  : Ii32<0x81, MRM2m, (outs), (ins i32mem:$dst, i32imm:$src2),
2683                       "adc{l}\t{$src2, $dst|$dst, $src2}",
2684                   [(store (adde (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2685   def ADC32mi8 : Ii8<0x83, MRM2m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2686                      "adc{l}\t{$src2, $dst|$dst, $src2}",
2687                [(store (adde (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2688
2689   def ADC8i8 : Ii8<0x14, RawFrm, (outs), (ins i8imm:$src),
2690                    "adc{b}\t{$src, %al|%al, $src}", []>;
2691   def ADC16i16 : Ii16<0x15, RawFrm, (outs), (ins i16imm:$src),
2692                       "adc{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2693   def ADC32i32 : Ii32<0x15, RawFrm, (outs), (ins i32imm:$src),
2694                       "adc{l}\t{$src, %eax|%eax, $src}", []>;
2695 } // Constraints = ""
2696 } // Uses = [EFLAGS]
2697
2698 // Register-Register Subtraction
2699 def SUB8rr  : I<0x28, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2700                 "sub{b}\t{$src2, $dst|$dst, $src2}",
2701                 [(set GR8:$dst, EFLAGS,
2702                       (X86sub_flag GR8:$src1, GR8:$src2))]>;
2703 def SUB16rr : I<0x29, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2704                 "sub{w}\t{$src2, $dst|$dst, $src2}",
2705                 [(set GR16:$dst, EFLAGS,
2706                       (X86sub_flag GR16:$src1, GR16:$src2))]>, OpSize;
2707 def SUB32rr : I<0x29, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
2708                 "sub{l}\t{$src2, $dst|$dst, $src2}",
2709                 [(set GR32:$dst, EFLAGS,
2710                       (X86sub_flag GR32:$src1, GR32:$src2))]>;
2711
2712 let isCodeGenOnly = 1 in {
2713 def SUB8rr_REV : I<0x2A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2714                    "sub{b}\t{$src2, $dst|$dst, $src2}", []>;
2715 def SUB16rr_REV : I<0x2B, MRMSrcReg, (outs GR16:$dst), 
2716                     (ins GR16:$src1, GR16:$src2),
2717                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2718 def SUB32rr_REV : I<0x2B, MRMSrcReg, (outs GR32:$dst), 
2719                     (ins GR32:$src1, GR32:$src2),
2720                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>;
2721 }
2722
2723 // Register-Memory Subtraction
2724 def SUB8rm  : I<0x2A, MRMSrcMem, (outs GR8 :$dst),
2725                                  (ins GR8 :$src1, i8mem :$src2),
2726                 "sub{b}\t{$src2, $dst|$dst, $src2}",
2727                 [(set GR8:$dst, EFLAGS,
2728                       (X86sub_flag GR8:$src1, (load addr:$src2)))]>;
2729 def SUB16rm : I<0x2B, MRMSrcMem, (outs GR16:$dst),
2730                                  (ins GR16:$src1, i16mem:$src2),
2731                 "sub{w}\t{$src2, $dst|$dst, $src2}",
2732                 [(set GR16:$dst, EFLAGS,
2733                       (X86sub_flag GR16:$src1, (load addr:$src2)))]>, OpSize;
2734 def SUB32rm : I<0x2B, MRMSrcMem, (outs GR32:$dst),
2735                                  (ins GR32:$src1, i32mem:$src2),
2736                 "sub{l}\t{$src2, $dst|$dst, $src2}",
2737                 [(set GR32:$dst, EFLAGS,
2738                       (X86sub_flag GR32:$src1, (load addr:$src2)))]>;
2739
2740 // Register-Integer Subtraction
2741 def SUB8ri   : Ii8 <0x80, MRM5r, (outs GR8:$dst),
2742                                  (ins GR8:$src1, i8imm:$src2),
2743                     "sub{b}\t{$src2, $dst|$dst, $src2}",
2744                     [(set GR8:$dst, EFLAGS,
2745                           (X86sub_flag GR8:$src1, imm:$src2))]>;
2746 def SUB16ri  : Ii16<0x81, MRM5r, (outs GR16:$dst),
2747                                  (ins GR16:$src1, i16imm:$src2),
2748                     "sub{w}\t{$src2, $dst|$dst, $src2}",
2749                     [(set GR16:$dst, EFLAGS,
2750                           (X86sub_flag GR16:$src1, imm:$src2))]>, OpSize;
2751 def SUB32ri  : Ii32<0x81, MRM5r, (outs GR32:$dst),
2752                                  (ins GR32:$src1, i32imm:$src2),
2753                     "sub{l}\t{$src2, $dst|$dst, $src2}",
2754                     [(set GR32:$dst, EFLAGS,
2755                           (X86sub_flag GR32:$src1, imm:$src2))]>;
2756 def SUB16ri8 : Ii8<0x83, MRM5r, (outs GR16:$dst),
2757                                 (ins GR16:$src1, i16i8imm:$src2),
2758                    "sub{w}\t{$src2, $dst|$dst, $src2}",
2759                    [(set GR16:$dst, EFLAGS,
2760                          (X86sub_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
2761 def SUB32ri8 : Ii8<0x83, MRM5r, (outs GR32:$dst),
2762                                 (ins GR32:$src1, i32i8imm:$src2),
2763                    "sub{l}\t{$src2, $dst|$dst, $src2}",
2764                    [(set GR32:$dst, EFLAGS,
2765                          (X86sub_flag GR32:$src1, i32immSExt8:$src2))]>;
2766
2767 let Constraints = "" in {
2768   // Memory-Register Subtraction
2769   def SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
2770                    "sub{b}\t{$src2, $dst|$dst, $src2}",
2771                    [(store (sub (load addr:$dst), GR8:$src2), addr:$dst),
2772                     (implicit EFLAGS)]>;
2773   def SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2774                    "sub{w}\t{$src2, $dst|$dst, $src2}",
2775                    [(store (sub (load addr:$dst), GR16:$src2), addr:$dst),
2776                     (implicit EFLAGS)]>, OpSize;
2777   def SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
2778                    "sub{l}\t{$src2, $dst|$dst, $src2}",
2779                    [(store (sub (load addr:$dst), GR32:$src2), addr:$dst),
2780                     (implicit EFLAGS)]>;
2781
2782   // Memory-Integer Subtraction
2783   def SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
2784                      "sub{b}\t{$src2, $dst|$dst, $src2}",
2785                      [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst),
2786                       (implicit EFLAGS)]>;
2787   def SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
2788                       "sub{w}\t{$src2, $dst|$dst, $src2}",
2789                       [(store (sub (loadi16 addr:$dst), imm:$src2),addr:$dst),
2790                        (implicit EFLAGS)]>, OpSize;
2791   def SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
2792                       "sub{l}\t{$src2, $dst|$dst, $src2}",
2793                       [(store (sub (loadi32 addr:$dst), imm:$src2),addr:$dst),
2794                        (implicit EFLAGS)]>;
2795   def SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
2796                      "sub{w}\t{$src2, $dst|$dst, $src2}",
2797                      [(store (sub (load addr:$dst), i16immSExt8:$src2),
2798                              addr:$dst),
2799                       (implicit EFLAGS)]>, OpSize;
2800   def SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2801                      "sub{l}\t{$src2, $dst|$dst, $src2}",
2802                      [(store (sub (load addr:$dst), i32immSExt8:$src2),
2803                              addr:$dst),
2804                       (implicit EFLAGS)]>;
2805                       
2806   def SUB8i8 : Ii8<0x2C, RawFrm, (outs), (ins i8imm:$src),
2807                    "sub{b}\t{$src, %al|%al, $src}", []>;
2808   def SUB16i16 : Ii16<0x2D, RawFrm, (outs), (ins i16imm:$src),
2809                       "sub{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2810   def SUB32i32 : Ii32<0x2D, RawFrm, (outs), (ins i32imm:$src),
2811                       "sub{l}\t{$src, %eax|%eax, $src}", []>;
2812 } // Constraints = ""
2813
2814 let Uses = [EFLAGS] in {
2815 def SBB8rr     : I<0x18, MRMDestReg, (outs GR8:$dst),
2816                                      (ins GR8:$src1, GR8:$src2),
2817                   "sbb{b}\t{$src2, $dst|$dst, $src2}",
2818                  [(set GR8:$dst, (sube GR8:$src1, GR8:$src2))]>;
2819 def SBB16rr    : I<0x19, MRMDestReg, (outs GR16:$dst),
2820                                      (ins GR16:$src1, GR16:$src2),
2821                   "sbb{w}\t{$src2, $dst|$dst, $src2}",
2822                  [(set GR16:$dst, (sube GR16:$src1, GR16:$src2))]>, OpSize;
2823 def SBB32rr    : I<0x19, MRMDestReg, (outs GR32:$dst),
2824                                       (ins GR32:$src1, GR32:$src2),
2825                   "sbb{l}\t{$src2, $dst|$dst, $src2}",
2826                  [(set GR32:$dst, (sube GR32:$src1, GR32:$src2))]>;
2827
2828 let Constraints = "" in {
2829   def SBB8mr   : I<0x18, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2), 
2830                    "sbb{b}\t{$src2, $dst|$dst, $src2}",
2831                    [(store (sube (load addr:$dst), GR8:$src2), addr:$dst)]>;
2832   def SBB16mr  : I<0x19, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2), 
2833                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
2834                    [(store (sube (load addr:$dst), GR16:$src2), addr:$dst)]>,
2835                    OpSize;
2836   def SBB32mr  : I<0x19, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
2837                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
2838                    [(store (sube (load addr:$dst), GR32:$src2), addr:$dst)]>;
2839   def SBB8mi  : Ii8<0x80, MRM3m, (outs), (ins i8mem:$dst, i8imm:$src2), 
2840                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
2841                    [(store (sube (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2842   def SBB16mi  : Ii16<0x81, MRM3m, (outs), (ins i16mem:$dst, i16imm:$src2), 
2843                       "sbb{w}\t{$src2, $dst|$dst, $src2}",
2844                   [(store (sube (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2845                   OpSize;
2846   def SBB16mi8 : Ii8<0x83, MRM3m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
2847                      "sbb{w}\t{$src2, $dst|$dst, $src2}",
2848                [(store (sube (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2849                OpSize;
2850   def SBB32mi  : Ii32<0x81, MRM3m, (outs), (ins i32mem:$dst, i32imm:$src2), 
2851                       "sbb{l}\t{$src2, $dst|$dst, $src2}",
2852                   [(store (sube (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2853   def SBB32mi8 : Ii8<0x83, MRM3m, (outs), (ins i32mem:$dst, i32i8imm :$src2), 
2854                      "sbb{l}\t{$src2, $dst|$dst, $src2}",
2855                [(store (sube (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2856                
2857   def SBB8i8 : Ii8<0x1C, RawFrm, (outs), (ins i8imm:$src),
2858                    "sbb{b}\t{$src, %al|%al, $src}", []>;
2859   def SBB16i16 : Ii16<0x1D, RawFrm, (outs), (ins i16imm:$src),
2860                       "sbb{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2861   def SBB32i32 : Ii32<0x1D, RawFrm, (outs), (ins i32imm:$src),
2862                       "sbb{l}\t{$src, %eax|%eax, $src}", []>;
2863 } // Constraints = ""
2864
2865 let isCodeGenOnly = 1 in {
2866 def SBB8rr_REV : I<0x1A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2867                    "sbb{b}\t{$src2, $dst|$dst, $src2}", []>;
2868 def SBB16rr_REV : I<0x1B, MRMSrcReg, (outs GR16:$dst), 
2869                     (ins GR16:$src1, GR16:$src2),
2870                     "sbb{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2871 def SBB32rr_REV : I<0x1B, MRMSrcReg, (outs GR32:$dst), 
2872                     (ins GR32:$src1, GR32:$src2),
2873                     "sbb{l}\t{$src2, $dst|$dst, $src2}", []>;
2874 }
2875
2876 def SBB8rm   : I<0x1A, MRMSrcMem, (outs GR8:$dst), (ins GR8:$src1, i8mem:$src2),
2877                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
2878                     [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2)))]>;
2879 def SBB16rm  : I<0x1B, MRMSrcMem, (outs GR16:$dst),
2880                                   (ins GR16:$src1, i16mem:$src2),
2881                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
2882                     [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2)))]>,
2883                     OpSize;
2884 def SBB32rm  : I<0x1B, MRMSrcMem, (outs GR32:$dst),
2885                                   (ins GR32:$src1, i32mem:$src2),
2886                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
2887                     [(set GR32:$dst, (sube GR32:$src1, (load addr:$src2)))]>;
2888 def SBB8ri   : Ii8<0x80, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2889                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
2890                     [(set GR8:$dst, (sube GR8:$src1, imm:$src2))]>;
2891 def SBB16ri  : Ii16<0x81, MRM3r, (outs GR16:$dst),
2892                                  (ins GR16:$src1, i16imm:$src2),
2893                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
2894                     [(set GR16:$dst, (sube GR16:$src1, imm:$src2))]>, OpSize;
2895 def SBB16ri8 : Ii8<0x83, MRM3r, (outs GR16:$dst),
2896                                 (ins GR16:$src1, i16i8imm:$src2),
2897                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
2898                    [(set GR16:$dst, (sube GR16:$src1, i16immSExt8:$src2))]>,
2899                    OpSize;
2900 def SBB32ri  : Ii32<0x81, MRM3r, (outs GR32:$dst), 
2901                                  (ins GR32:$src1, i32imm:$src2),
2902                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
2903                     [(set GR32:$dst, (sube GR32:$src1, imm:$src2))]>;
2904 def SBB32ri8 : Ii8<0x83, MRM3r, (outs GR32:$dst),
2905                                 (ins GR32:$src1, i32i8imm:$src2),
2906                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
2907                    [(set GR32:$dst, (sube GR32:$src1, i32immSExt8:$src2))]>;
2908 } // Uses = [EFLAGS]
2909 } // Defs = [EFLAGS]
2910
2911 let Defs = [EFLAGS] in {
2912 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
2913 // Register-Register Signed Integer Multiply
2914 def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2915                  "imul{w}\t{$src2, $dst|$dst, $src2}",
2916                  [(set GR16:$dst, EFLAGS,
2917                        (X86smul_flag GR16:$src1, GR16:$src2))]>, TB, OpSize;
2918 def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
2919                  "imul{l}\t{$src2, $dst|$dst, $src2}",
2920                  [(set GR32:$dst, EFLAGS,
2921                        (X86smul_flag GR32:$src1, GR32:$src2))]>, TB;
2922 }
2923
2924 // Register-Memory Signed Integer Multiply
2925 def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
2926                                   (ins GR16:$src1, i16mem:$src2),
2927                  "imul{w}\t{$src2, $dst|$dst, $src2}",
2928                  [(set GR16:$dst, EFLAGS,
2929                        (X86smul_flag GR16:$src1, (load addr:$src2)))]>,
2930                TB, OpSize;
2931 def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst), 
2932                  (ins GR32:$src1, i32mem:$src2),
2933                  "imul{l}\t{$src2, $dst|$dst, $src2}",
2934                  [(set GR32:$dst, EFLAGS,
2935                        (X86smul_flag GR32:$src1, (load addr:$src2)))]>, TB;
2936 } // Defs = [EFLAGS]
2937 } // end Two Address instructions
2938
2939 // Suprisingly enough, these are not two address instructions!
2940 let Defs = [EFLAGS] in {
2941 // Register-Integer Signed Integer Multiply
2942 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // GR16 = GR16*I16
2943                       (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
2944                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2945                       [(set GR16:$dst, EFLAGS, 
2946                             (X86smul_flag GR16:$src1, imm:$src2))]>, OpSize;
2947 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // GR32 = GR32*I32
2948                       (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
2949                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2950                       [(set GR32:$dst, EFLAGS,
2951                             (X86smul_flag GR32:$src1, imm:$src2))]>;
2952 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // GR16 = GR16*I8
2953                      (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
2954                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2955                      [(set GR16:$dst, EFLAGS,
2956                            (X86smul_flag GR16:$src1, i16immSExt8:$src2))]>,
2957                  OpSize;
2958 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // GR32 = GR32*I8
2959                      (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
2960                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2961                      [(set GR32:$dst, EFLAGS,
2962                            (X86smul_flag GR32:$src1, i32immSExt8:$src2))]>;
2963
2964 // Memory-Integer Signed Integer Multiply
2965 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                     // GR16 = [mem16]*I16
2966                       (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
2967                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2968                       [(set GR16:$dst, EFLAGS,
2969                             (X86smul_flag (load addr:$src1), imm:$src2))]>,
2970                  OpSize;
2971 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                     // GR32 = [mem32]*I32
2972                       (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
2973                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2974                       [(set GR32:$dst, EFLAGS,
2975                             (X86smul_flag (load addr:$src1), imm:$src2))]>;
2976 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR16 = [mem16]*I8
2977                      (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
2978                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2979                      [(set GR16:$dst, EFLAGS,
2980                            (X86smul_flag (load addr:$src1),
2981                                          i16immSExt8:$src2))]>, OpSize;
2982 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR32 = [mem32]*I8
2983                      (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
2984                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
2985                      [(set GR32:$dst, EFLAGS,
2986                            (X86smul_flag (load addr:$src1),
2987                                          i32immSExt8:$src2))]>;
2988 } // Defs = [EFLAGS]
2989
2990 //===----------------------------------------------------------------------===//
2991 // Test instructions are just like AND, except they don't generate a result.
2992 //
2993 let Defs = [EFLAGS] in {
2994 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
2995 def TEST8rr  : I<0x84, MRMSrcReg, (outs),  (ins GR8:$src1, GR8:$src2),
2996                      "test{b}\t{$src2, $src1|$src1, $src2}",
2997                      [(set EFLAGS, (X86cmp (and_su GR8:$src1, GR8:$src2), 0))]>;
2998 def TEST16rr : I<0x85, MRMSrcReg, (outs),  (ins GR16:$src1, GR16:$src2),
2999                      "test{w}\t{$src2, $src1|$src1, $src2}",
3000                      [(set EFLAGS, (X86cmp (and_su GR16:$src1, GR16:$src2),
3001                       0))]>,
3002                  OpSize;
3003 def TEST32rr : I<0x85, MRMSrcReg, (outs),  (ins GR32:$src1, GR32:$src2),
3004                      "test{l}\t{$src2, $src1|$src1, $src2}",
3005                      [(set EFLAGS, (X86cmp (and_su GR32:$src1, GR32:$src2),
3006                       0))]>;
3007 }
3008
3009 def TEST8i8  : Ii8<0xA8, RawFrm, (outs), (ins i8imm:$src),
3010                    "test{b}\t{$src, %al|%al, $src}", []>;
3011 def TEST16i16 : Ii16<0xA9, RawFrm, (outs), (ins i16imm:$src),
3012                      "test{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3013 def TEST32i32 : Ii32<0xA9, RawFrm, (outs), (ins i32imm:$src),
3014                      "test{l}\t{$src, %eax|%eax, $src}", []>;
3015
3016 def TEST8rm  : I<0x84, MRMSrcMem, (outs),  (ins GR8 :$src1, i8mem :$src2),
3017                      "test{b}\t{$src2, $src1|$src1, $src2}",
3018                      [(set EFLAGS, (X86cmp (and GR8:$src1, (loadi8 addr:$src2)),
3019                        0))]>;
3020 def TEST16rm : I<0x85, MRMSrcMem, (outs),  (ins GR16:$src1, i16mem:$src2),
3021                      "test{w}\t{$src2, $src1|$src1, $src2}",
3022                      [(set EFLAGS, (X86cmp (and GR16:$src1,
3023                                          (loadi16 addr:$src2)), 0))]>, OpSize;
3024 def TEST32rm : I<0x85, MRMSrcMem, (outs),  (ins GR32:$src1, i32mem:$src2),
3025                      "test{l}\t{$src2, $src1|$src1, $src2}",
3026                      [(set EFLAGS, (X86cmp (and GR32:$src1,
3027                                                 (loadi32 addr:$src2)), 0))]>;
3028
3029 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = GR8  & imm8
3030                     (outs),  (ins GR8:$src1, i8imm:$src2),
3031                     "test{b}\t{$src2, $src1|$src1, $src2}",
3032                     [(set EFLAGS, (X86cmp (and_su GR8:$src1, imm:$src2), 0))]>;
3033 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = GR16 & imm16
3034                     (outs),  (ins GR16:$src1, i16imm:$src2),
3035                     "test{w}\t{$src2, $src1|$src1, $src2}",
3036                     [(set EFLAGS, (X86cmp (and_su GR16:$src1, imm:$src2), 0))]>,
3037                     OpSize;
3038 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = GR32 & imm32
3039                     (outs),  (ins GR32:$src1, i32imm:$src2),
3040                     "test{l}\t{$src2, $src1|$src1, $src2}",
3041                     [(set EFLAGS, (X86cmp (and_su GR32:$src1, imm:$src2), 0))]>;
3042
3043 def TEST8mi  : Ii8 <0xF6, MRM0m,                   // flags = [mem8]  & imm8
3044                     (outs), (ins i8mem:$src1, i8imm:$src2),
3045                     "test{b}\t{$src2, $src1|$src1, $src2}",
3046                     [(set EFLAGS, (X86cmp (and (loadi8 addr:$src1), imm:$src2),
3047                      0))]>;
3048 def TEST16mi : Ii16<0xF7, MRM0m,                   // flags = [mem16] & imm16
3049                     (outs), (ins i16mem:$src1, i16imm:$src2),
3050                     "test{w}\t{$src2, $src1|$src1, $src2}",
3051                     [(set EFLAGS, (X86cmp (and (loadi16 addr:$src1), imm:$src2),
3052                      0))]>, OpSize;
3053 def TEST32mi : Ii32<0xF7, MRM0m,                   // flags = [mem32] & imm32
3054                     (outs), (ins i32mem:$src1, i32imm:$src2),
3055                     "test{l}\t{$src2, $src1|$src1, $src2}",
3056                     [(set EFLAGS, (X86cmp (and (loadi32 addr:$src1), imm:$src2),
3057                      0))]>;
3058 } // Defs = [EFLAGS]
3059
3060
3061 // Condition code ops, incl. set if equal/not equal/...
3062 let Defs = [EFLAGS], Uses = [AH], neverHasSideEffects = 1 in
3063 def SAHF     : I<0x9E, RawFrm, (outs),  (ins), "sahf", []>;  // flags = AH
3064 let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
3065 def LAHF     : I<0x9F, RawFrm, (outs),  (ins), "lahf", []>;  // AH = flags
3066
3067 let Uses = [EFLAGS] in {
3068 // Use sbb to materialize carry bit.
3069 let Defs = [EFLAGS], isCodeGenOnly = 1 in {
3070 // FIXME: These are pseudo ops that should be replaced with Pat<> patterns.
3071 // However, Pat<> can't replicate the destination reg into the inputs of the
3072 // result.
3073 // FIXME: Change these to have encoding Pseudo when X86MCCodeEmitter replaces
3074 // X86CodeEmitter.
3075 def SETB_C8r : I<0x18, MRMInitReg, (outs GR8:$dst), (ins), "",
3076                  [(set GR8:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
3077 def SETB_C16r : I<0x19, MRMInitReg, (outs GR16:$dst), (ins), "",
3078                  [(set GR16:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>,
3079                 OpSize;
3080 def SETB_C32r : I<0x19, MRMInitReg, (outs GR32:$dst), (ins), "",
3081                  [(set GR32:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
3082 } // isCodeGenOnly
3083
3084 def SETEr    : I<0x94, MRM0r, 
3085                  (outs GR8   :$dst), (ins),
3086                  "sete\t$dst",
3087                  [(set GR8:$dst, (X86setcc X86_COND_E, EFLAGS))]>,
3088                TB;                        // GR8 = ==
3089 def SETEm    : I<0x94, MRM0m, 
3090                  (outs), (ins i8mem:$dst),
3091                  "sete\t$dst",
3092                  [(store (X86setcc X86_COND_E, EFLAGS), addr:$dst)]>,
3093                TB;                        // [mem8] = ==
3094
3095 def SETNEr   : I<0x95, MRM0r, 
3096                  (outs GR8   :$dst), (ins),
3097                  "setne\t$dst",
3098                  [(set GR8:$dst, (X86setcc X86_COND_NE, EFLAGS))]>,
3099                TB;                        // GR8 = !=
3100 def SETNEm   : I<0x95, MRM0m, 
3101                  (outs), (ins i8mem:$dst),
3102                  "setne\t$dst",
3103                  [(store (X86setcc X86_COND_NE, EFLAGS), addr:$dst)]>,
3104                TB;                        // [mem8] = !=
3105
3106 def SETLr    : I<0x9C, MRM0r, 
3107                  (outs GR8   :$dst), (ins),
3108                  "setl\t$dst",
3109                  [(set GR8:$dst, (X86setcc X86_COND_L, EFLAGS))]>,
3110                TB;                        // GR8 = <  signed
3111 def SETLm    : I<0x9C, MRM0m, 
3112                  (outs), (ins i8mem:$dst),
3113                  "setl\t$dst",
3114                  [(store (X86setcc X86_COND_L, EFLAGS), addr:$dst)]>,
3115                TB;                        // [mem8] = <  signed
3116
3117 def SETGEr   : I<0x9D, MRM0r, 
3118                  (outs GR8   :$dst), (ins),
3119                  "setge\t$dst",
3120                  [(set GR8:$dst, (X86setcc X86_COND_GE, EFLAGS))]>,
3121                TB;                        // GR8 = >= signed
3122 def SETGEm   : I<0x9D, MRM0m, 
3123                  (outs), (ins i8mem:$dst),
3124                  "setge\t$dst",
3125                  [(store (X86setcc X86_COND_GE, EFLAGS), addr:$dst)]>,
3126                TB;                        // [mem8] = >= signed
3127
3128 def SETLEr   : I<0x9E, MRM0r, 
3129                  (outs GR8   :$dst), (ins),
3130                  "setle\t$dst",
3131                  [(set GR8:$dst, (X86setcc X86_COND_LE, EFLAGS))]>,
3132                TB;                        // GR8 = <= signed
3133 def SETLEm   : I<0x9E, MRM0m, 
3134                  (outs), (ins i8mem:$dst),
3135                  "setle\t$dst",
3136                  [(store (X86setcc X86_COND_LE, EFLAGS), addr:$dst)]>,
3137                TB;                        // [mem8] = <= signed
3138
3139 def SETGr    : I<0x9F, MRM0r, 
3140                  (outs GR8   :$dst), (ins),
3141                  "setg\t$dst",
3142                  [(set GR8:$dst, (X86setcc X86_COND_G, EFLAGS))]>,
3143                TB;                        // GR8 = >  signed
3144 def SETGm    : I<0x9F, MRM0m, 
3145                  (outs), (ins i8mem:$dst),
3146                  "setg\t$dst",
3147                  [(store (X86setcc X86_COND_G, EFLAGS), addr:$dst)]>,
3148                TB;                        // [mem8] = >  signed
3149
3150 def SETBr    : I<0x92, MRM0r,
3151                  (outs GR8   :$dst), (ins),
3152                  "setb\t$dst",
3153                  [(set GR8:$dst, (X86setcc X86_COND_B, EFLAGS))]>,
3154                TB;                        // GR8 = <  unsign
3155 def SETBm    : I<0x92, MRM0m,
3156                  (outs), (ins i8mem:$dst),
3157                  "setb\t$dst",
3158                  [(store (X86setcc X86_COND_B, EFLAGS), addr:$dst)]>,
3159                TB;                        // [mem8] = <  unsign
3160
3161 def SETAEr   : I<0x93, MRM0r, 
3162                  (outs GR8   :$dst), (ins),
3163                  "setae\t$dst",
3164                  [(set GR8:$dst, (X86setcc X86_COND_AE, EFLAGS))]>,
3165                TB;                        // GR8 = >= unsign
3166 def SETAEm   : I<0x93, MRM0m, 
3167                  (outs), (ins i8mem:$dst),
3168                  "setae\t$dst",
3169                  [(store (X86setcc X86_COND_AE, EFLAGS), addr:$dst)]>,
3170                TB;                        // [mem8] = >= unsign
3171
3172 def SETBEr   : I<0x96, MRM0r, 
3173                  (outs GR8   :$dst), (ins),
3174                  "setbe\t$dst",
3175                  [(set GR8:$dst, (X86setcc X86_COND_BE, EFLAGS))]>,
3176                TB;                        // GR8 = <= unsign
3177 def SETBEm   : I<0x96, MRM0m, 
3178                  (outs), (ins i8mem:$dst),
3179                  "setbe\t$dst",
3180                  [(store (X86setcc X86_COND_BE, EFLAGS), addr:$dst)]>,
3181                TB;                        // [mem8] = <= unsign
3182
3183 def SETAr    : I<0x97, MRM0r, 
3184                  (outs GR8   :$dst), (ins),
3185                  "seta\t$dst",
3186                  [(set GR8:$dst, (X86setcc X86_COND_A, EFLAGS))]>,
3187                TB;                        // GR8 = >  signed
3188 def SETAm    : I<0x97, MRM0m, 
3189                  (outs), (ins i8mem:$dst),
3190                  "seta\t$dst",
3191                  [(store (X86setcc X86_COND_A, EFLAGS), addr:$dst)]>,
3192                TB;                        // [mem8] = >  signed
3193
3194 def SETSr    : I<0x98, MRM0r, 
3195                  (outs GR8   :$dst), (ins),
3196                  "sets\t$dst",
3197                  [(set GR8:$dst, (X86setcc X86_COND_S, EFLAGS))]>,
3198                TB;                        // GR8 = <sign bit>
3199 def SETSm    : I<0x98, MRM0m, 
3200                  (outs), (ins i8mem:$dst),
3201                  "sets\t$dst",
3202                  [(store (X86setcc X86_COND_S, EFLAGS), addr:$dst)]>,
3203                TB;                        // [mem8] = <sign bit>
3204 def SETNSr   : I<0x99, MRM0r, 
3205                  (outs GR8   :$dst), (ins),
3206                  "setns\t$dst",
3207                  [(set GR8:$dst, (X86setcc X86_COND_NS, EFLAGS))]>,
3208                TB;                        // GR8 = !<sign bit>
3209 def SETNSm   : I<0x99, MRM0m, 
3210                  (outs), (ins i8mem:$dst),
3211                  "setns\t$dst",
3212                  [(store (X86setcc X86_COND_NS, EFLAGS), addr:$dst)]>,
3213                TB;                        // [mem8] = !<sign bit>
3214
3215 def SETPr    : I<0x9A, MRM0r, 
3216                  (outs GR8   :$dst), (ins),
3217                  "setp\t$dst",
3218                  [(set GR8:$dst, (X86setcc X86_COND_P, EFLAGS))]>,
3219                TB;                        // GR8 = parity
3220 def SETPm    : I<0x9A, MRM0m, 
3221                  (outs), (ins i8mem:$dst),
3222                  "setp\t$dst",
3223                  [(store (X86setcc X86_COND_P, EFLAGS), addr:$dst)]>,
3224                TB;                        // [mem8] = parity
3225 def SETNPr   : I<0x9B, MRM0r, 
3226                  (outs GR8   :$dst), (ins),
3227                  "setnp\t$dst",
3228                  [(set GR8:$dst, (X86setcc X86_COND_NP, EFLAGS))]>,
3229                TB;                        // GR8 = not parity
3230 def SETNPm   : I<0x9B, MRM0m, 
3231                  (outs), (ins i8mem:$dst),
3232                  "setnp\t$dst",
3233                  [(store (X86setcc X86_COND_NP, EFLAGS), addr:$dst)]>,
3234                TB;                        // [mem8] = not parity
3235
3236 def SETOr    : I<0x90, MRM0r, 
3237                  (outs GR8   :$dst), (ins),
3238                  "seto\t$dst",
3239                  [(set GR8:$dst, (X86setcc X86_COND_O, EFLAGS))]>,
3240                TB;                        // GR8 = overflow
3241 def SETOm    : I<0x90, MRM0m, 
3242                  (outs), (ins i8mem:$dst),
3243                  "seto\t$dst",
3244                  [(store (X86setcc X86_COND_O, EFLAGS), addr:$dst)]>,
3245                TB;                        // [mem8] = overflow
3246 def SETNOr   : I<0x91, MRM0r, 
3247                  (outs GR8   :$dst), (ins),
3248                  "setno\t$dst",
3249                  [(set GR8:$dst, (X86setcc X86_COND_NO, EFLAGS))]>,
3250                TB;                        // GR8 = not overflow
3251 def SETNOm   : I<0x91, MRM0m, 
3252                  (outs), (ins i8mem:$dst),
3253                  "setno\t$dst",
3254                  [(store (X86setcc X86_COND_NO, EFLAGS), addr:$dst)]>,
3255                TB;                        // [mem8] = not overflow
3256 } // Uses = [EFLAGS]
3257
3258
3259 // Integer comparisons
3260 let Defs = [EFLAGS] in {
3261 def CMP8i8 : Ii8<0x3C, RawFrm, (outs), (ins i8imm:$src),
3262                  "cmp{b}\t{$src, %al|%al, $src}", []>;
3263 def CMP16i16 : Ii16<0x3D, RawFrm, (outs), (ins i16imm:$src),
3264                     "cmp{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3265 def CMP32i32 : Ii32<0x3D, RawFrm, (outs), (ins i32imm:$src),
3266                     "cmp{l}\t{$src, %eax|%eax, $src}", []>;
3267
3268 def CMP8rr  : I<0x38, MRMDestReg,
3269                 (outs), (ins GR8 :$src1, GR8 :$src2),
3270                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3271                 [(set EFLAGS, (X86cmp GR8:$src1, GR8:$src2))]>;
3272 def CMP16rr : I<0x39, MRMDestReg,
3273                 (outs), (ins GR16:$src1, GR16:$src2),
3274                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3275                 [(set EFLAGS, (X86cmp GR16:$src1, GR16:$src2))]>, OpSize;
3276 def CMP32rr : I<0x39, MRMDestReg,
3277                 (outs), (ins GR32:$src1, GR32:$src2),
3278                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3279                 [(set EFLAGS, (X86cmp GR32:$src1, GR32:$src2))]>;
3280 def CMP8mr  : I<0x38, MRMDestMem,
3281                 (outs), (ins i8mem :$src1, GR8 :$src2),
3282                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3283                 [(set EFLAGS, (X86cmp (loadi8 addr:$src1), GR8:$src2))]>;
3284 def CMP16mr : I<0x39, MRMDestMem,
3285                 (outs), (ins i16mem:$src1, GR16:$src2),
3286                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3287                 [(set EFLAGS, (X86cmp (loadi16 addr:$src1), GR16:$src2))]>,
3288                  OpSize;
3289 def CMP32mr : I<0x39, MRMDestMem,
3290                 (outs), (ins i32mem:$src1, GR32:$src2),
3291                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3292                 [(set EFLAGS, (X86cmp (loadi32 addr:$src1), GR32:$src2))]>;
3293 def CMP8rm  : I<0x3A, MRMSrcMem,
3294                 (outs), (ins GR8 :$src1, i8mem :$src2),
3295                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3296                 [(set EFLAGS, (X86cmp GR8:$src1, (loadi8 addr:$src2)))]>;
3297 def CMP16rm : I<0x3B, MRMSrcMem,
3298                 (outs), (ins GR16:$src1, i16mem:$src2),
3299                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3300                 [(set EFLAGS, (X86cmp GR16:$src1, (loadi16 addr:$src2)))]>,
3301                  OpSize;
3302 def CMP32rm : I<0x3B, MRMSrcMem,
3303                 (outs), (ins GR32:$src1, i32mem:$src2),
3304                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3305                 [(set EFLAGS, (X86cmp GR32:$src1, (loadi32 addr:$src2)))]>;
3306
3307 // These are alternate spellings for use by the disassembler, we mark them as
3308 // code gen only to ensure they aren't matched by the assembler.
3309 let isCodeGenOnly = 1 in {
3310   def CMP8rr_alt : I<0x3A, MRMSrcReg, (outs), (ins GR8:$src1, GR8:$src2),
3311                     "cmp{b}\t{$src2, $src1|$src1, $src2}", []>;
3312   def CMP16rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR16:$src1, GR16:$src2),
3313                      "cmp{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize;
3314   def CMP32rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR32:$src1, GR32:$src2),
3315                      "cmp{l}\t{$src2, $src1|$src1, $src2}", []>;
3316 }
3317
3318 def CMP8ri  : Ii8<0x80, MRM7r,
3319                   (outs), (ins GR8:$src1, i8imm:$src2),
3320                   "cmp{b}\t{$src2, $src1|$src1, $src2}",
3321                   [(set EFLAGS, (X86cmp GR8:$src1, imm:$src2))]>;
3322 def CMP16ri : Ii16<0x81, MRM7r,
3323                    (outs), (ins GR16:$src1, i16imm:$src2),
3324                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3325                    [(set EFLAGS, (X86cmp GR16:$src1, imm:$src2))]>, OpSize;
3326 def CMP32ri : Ii32<0x81, MRM7r,
3327                    (outs), (ins GR32:$src1, i32imm:$src2),
3328                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3329                    [(set EFLAGS, (X86cmp GR32:$src1, imm:$src2))]>;
3330 def CMP8mi  : Ii8 <0x80, MRM7m,
3331                    (outs), (ins i8mem :$src1, i8imm :$src2),
3332                    "cmp{b}\t{$src2, $src1|$src1, $src2}",
3333                    [(set EFLAGS, (X86cmp (loadi8 addr:$src1), imm:$src2))]>;
3334 def CMP16mi : Ii16<0x81, MRM7m,
3335                    (outs), (ins i16mem:$src1, i16imm:$src2),
3336                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3337                    [(set EFLAGS, (X86cmp (loadi16 addr:$src1), imm:$src2))]>,
3338                    OpSize;
3339 def CMP32mi : Ii32<0x81, MRM7m,
3340                    (outs), (ins i32mem:$src1, i32imm:$src2),
3341                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3342                    [(set EFLAGS, (X86cmp (loadi32 addr:$src1), imm:$src2))]>;
3343 def CMP16ri8 : Ii8<0x83, MRM7r,
3344                    (outs), (ins GR16:$src1, i16i8imm:$src2),
3345                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3346                    [(set EFLAGS, (X86cmp GR16:$src1, i16immSExt8:$src2))]>,
3347                     OpSize;
3348 def CMP16mi8 : Ii8<0x83, MRM7m,
3349                    (outs), (ins i16mem:$src1, i16i8imm:$src2),
3350                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3351                    [(set EFLAGS, (X86cmp (loadi16 addr:$src1),
3352                                          i16immSExt8:$src2))]>, OpSize;
3353 def CMP32mi8 : Ii8<0x83, MRM7m,
3354                    (outs), (ins i32mem:$src1, i32i8imm:$src2),
3355                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3356                    [(set EFLAGS, (X86cmp (loadi32 addr:$src1),
3357                                          i32immSExt8:$src2))]>;
3358 def CMP32ri8 : Ii8<0x83, MRM7r,
3359                    (outs), (ins GR32:$src1, i32i8imm:$src2),
3360                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3361                    [(set EFLAGS, (X86cmp GR32:$src1, i32immSExt8:$src2))]>;
3362 } // Defs = [EFLAGS]
3363
3364 // Bit tests.
3365 // TODO: BTC, BTR, and BTS
3366 let Defs = [EFLAGS] in {
3367 def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3368                "bt{w}\t{$src2, $src1|$src1, $src2}",
3369                [(set EFLAGS, (X86bt GR16:$src1, GR16:$src2))]>, OpSize, TB;
3370 def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3371                "bt{l}\t{$src2, $src1|$src1, $src2}",
3372                [(set EFLAGS, (X86bt GR32:$src1, GR32:$src2))]>, TB;
3373
3374 // Unlike with the register+register form, the memory+register form of the
3375 // bt instruction does not ignore the high bits of the index. From ISel's
3376 // perspective, this is pretty bizarre. Make these instructions disassembly
3377 // only for now.
3378
3379 def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3380                "bt{w}\t{$src2, $src1|$src1, $src2}", 
3381 //               [(X86bt (loadi16 addr:$src1), GR16:$src2),
3382 //                (implicit EFLAGS)]
3383                []
3384                >, OpSize, TB, Requires<[FastBTMem]>;
3385 def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3386                "bt{l}\t{$src2, $src1|$src1, $src2}", 
3387 //               [(X86bt (loadi32 addr:$src1), GR32:$src2),
3388 //                (implicit EFLAGS)]
3389                []
3390                >, TB, Requires<[FastBTMem]>;
3391
3392 def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3393                 "bt{w}\t{$src2, $src1|$src1, $src2}",
3394                 [(set EFLAGS, (X86bt GR16:$src1, i16immSExt8:$src2))]>,
3395                 OpSize, TB;
3396 def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3397                 "bt{l}\t{$src2, $src1|$src1, $src2}",
3398                 [(set EFLAGS, (X86bt GR32:$src1, i32immSExt8:$src2))]>, TB;
3399 // Note that these instructions don't need FastBTMem because that
3400 // only applies when the other operand is in a register. When it's
3401 // an immediate, bt is still fast.
3402 def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3403                 "bt{w}\t{$src2, $src1|$src1, $src2}",
3404                 [(set EFLAGS, (X86bt (loadi16 addr:$src1), i16immSExt8:$src2))
3405                  ]>, OpSize, TB;
3406 def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3407                 "bt{l}\t{$src2, $src1|$src1, $src2}",
3408                 [(set EFLAGS, (X86bt (loadi32 addr:$src1), i32immSExt8:$src2))
3409                  ]>, TB;
3410
3411 def BTC16rr : I<0xBB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3412                 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3413 def BTC32rr : I<0xBB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3414                 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3415 def BTC16mr : I<0xBB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3416                 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3417 def BTC32mr : I<0xBB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3418                 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3419 def BTC16ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3420                     "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3421 def BTC32ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3422                     "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3423 def BTC16mi8 : Ii8<0xBA, MRM7m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3424                     "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3425 def BTC32mi8 : Ii8<0xBA, MRM7m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3426                     "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3427
3428 def BTR16rr : I<0xB3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3429                 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3430 def BTR32rr : I<0xB3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3431                 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3432 def BTR16mr : I<0xB3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3433                 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3434 def BTR32mr : I<0xB3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3435                 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3436 def BTR16ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3437                     "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3438 def BTR32ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3439                     "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3440 def BTR16mi8 : Ii8<0xBA, MRM6m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3441                     "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3442 def BTR32mi8 : Ii8<0xBA, MRM6m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3443                     "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3444
3445 def BTS16rr : I<0xAB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3446                 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3447 def BTS32rr : I<0xAB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3448                 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3449 def BTS16mr : I<0xAB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3450                 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3451 def BTS32mr : I<0xAB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3452                 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3453 def BTS16ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3454                     "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3455 def BTS32ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3456                     "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3457 def BTS16mi8 : Ii8<0xBA, MRM5m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3458                     "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3459 def BTS32mi8 : Ii8<0xBA, MRM5m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3460                     "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3461 } // Defs = [EFLAGS]
3462
3463 // Sign/Zero extenders
3464 // Use movsbl intead of movsbw; we don't care about the high 16 bits
3465 // of the register here. This has a smaller encoding and avoids a
3466 // partial-register update.  Actual movsbw included for the disassembler.
3467 def MOVSX16rr8W : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
3468                     "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3469 def MOVSX16rm8W : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
3470                     "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3471 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
3472                    "", [(set GR16:$dst, (sext GR8:$src))]>, TB;
3473 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
3474                    "", [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB;
3475 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
3476                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
3477                    [(set GR32:$dst, (sext GR8:$src))]>, TB;
3478 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
3479                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
3480                    [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
3481 def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
3482                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
3483                    [(set GR32:$dst, (sext GR16:$src))]>, TB;
3484 def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
3485                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
3486                    [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
3487
3488 // Use movzbl intead of movzbw; we don't care about the high 16 bits
3489 // of the register here. This has a smaller encoding and avoids a
3490 // partial-register update.  Actual movzbw included for the disassembler.
3491 def MOVZX16rr8W : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
3492                     "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3493 def MOVZX16rm8W : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
3494                     "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;  
3495 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
3496                    "", [(set GR16:$dst, (zext GR8:$src))]>, TB;
3497 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
3498                    "", [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB;
3499 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
3500                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
3501                    [(set GR32:$dst, (zext GR8:$src))]>, TB;
3502 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
3503                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
3504                    [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
3505 def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
3506                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
3507                    [(set GR32:$dst, (zext GR16:$src))]>, TB;
3508 def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
3509                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
3510                    [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
3511
3512 // These are the same as the regular MOVZX32rr8 and MOVZX32rm8
3513 // except that they use GR32_NOREX for the output operand register class
3514 // instead of GR32. This allows them to operate on h registers on x86-64.
3515 def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
3516                          (outs GR32_NOREX:$dst), (ins GR8:$src),
3517                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
3518                          []>, TB;
3519 let mayLoad = 1 in
3520 def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
3521                          (outs GR32_NOREX:$dst), (ins i8mem:$src),
3522                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
3523                          []>, TB;
3524
3525 let neverHasSideEffects = 1 in {
3526   let Defs = [AX], Uses = [AL] in
3527   def CBW : I<0x98, RawFrm, (outs), (ins),
3528               "{cbtw|cbw}", []>, OpSize;   // AX = signext(AL)
3529   let Defs = [EAX], Uses = [AX] in
3530   def CWDE : I<0x98, RawFrm, (outs), (ins),
3531               "{cwtl|cwde}", []>;   // EAX = signext(AX)
3532
3533   let Defs = [AX,DX], Uses = [AX] in
3534   def CWD : I<0x99, RawFrm, (outs), (ins),
3535               "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
3536   let Defs = [EAX,EDX], Uses = [EAX] in
3537   def CDQ : I<0x99, RawFrm, (outs), (ins),
3538               "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
3539 }
3540
3541 //===----------------------------------------------------------------------===//
3542 // Alias Instructions
3543 //===----------------------------------------------------------------------===//
3544
3545 // Alias instructions that map movr0 to xor.
3546 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
3547 // FIXME: Set encoding to pseudo.
3548 let Defs = [EFLAGS], isReMaterializable = 1, isAsCheapAsAMove = 1,
3549     isCodeGenOnly = 1 in {
3550 def MOV8r0   : I<0x30, MRMInitReg, (outs GR8 :$dst), (ins), "",
3551                  [(set GR8:$dst, 0)]>;
3552
3553 // We want to rewrite MOV16r0 in terms of MOV32r0, because it's a smaller
3554 // encoding and avoids a partial-register update sometimes, but doing so
3555 // at isel time interferes with rematerialization in the current register
3556 // allocator. For now, this is rewritten when the instruction is lowered
3557 // to an MCInst.
3558 def MOV16r0   : I<0x31, MRMInitReg, (outs GR16:$dst), (ins),
3559                  "",
3560                  [(set GR16:$dst, 0)]>, OpSize;
3561                  
3562 // FIXME: Set encoding to pseudo.
3563 def MOV32r0  : I<0x31, MRMInitReg, (outs GR32:$dst), (ins), "",
3564                  [(set GR32:$dst, 0)]>;
3565 }
3566
3567 //===----------------------------------------------------------------------===//
3568 // Thread Local Storage Instructions
3569 //
3570
3571 // ELF TLS Support
3572 // All calls clobber the non-callee saved registers. ESP is marked as
3573 // a use to prevent stack-pointer assignments that appear immediately
3574 // before calls from potentially appearing dead.
3575 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
3576             MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
3577             XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
3578             XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
3579     Uses = [ESP] in
3580 def TLS_addr32 : I<0, Pseudo, (outs), (ins i32mem:$sym),
3581                   "leal\t$sym, %eax; "
3582                   "call\t___tls_get_addr@PLT",
3583                   [(X86tlsaddr tls32addr:$sym)]>,
3584                   Requires<[In32BitMode]>;
3585
3586 // Darwin TLS Support
3587 // For i386, the address of the thunk is passed on the stack, on return the 
3588 // address of the variable is in %eax.  %ecx is trashed during the function 
3589 // call.  All other registers are preserved.
3590 let Defs = [EAX, ECX],
3591     Uses = [ESP],
3592     usesCustomInserter = 1 in
3593 def TLSCall_32 : I<0, Pseudo, (outs), (ins i32mem:$sym),
3594                 "# TLSCall_32",
3595                 [(X86TLSCall addr:$sym)]>,
3596                 Requires<[In32BitMode]>;
3597                 
3598
3599 //===----------------------------------------------------------------------===//
3600 // Atomic support
3601 //
3602
3603 // Memory barriers
3604
3605 // TODO: Get this to fold the constant into the instruction.           
3606 def OR32mrLocked  : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$zero),
3607                       "lock\n\t"
3608                       "or{l}\t{$zero, $dst|$dst, $zero}",
3609                       []>, Requires<[In32BitMode]>, LOCK;
3610
3611 let hasSideEffects = 1 in {
3612 def Int_MemBarrier : I<0, Pseudo, (outs), (ins),
3613                      "#MEMBARRIER",
3614                      [(X86MemBarrier)]>, Requires<[HasSSE2]>;
3615 }
3616
3617 // Atomic swap. These are just normal xchg instructions. But since a memory
3618 // operand is referenced, the atomicity is ensured.
3619 let Constraints = "$val = $dst" in {
3620 def XCHG32rm : I<0x87, MRMSrcMem, (outs GR32:$dst), 
3621                  (ins GR32:$val, i32mem:$ptr),
3622                "xchg{l}\t{$val, $ptr|$ptr, $val}", 
3623                [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))]>;
3624 def XCHG16rm : I<0x87, MRMSrcMem, (outs GR16:$dst), 
3625                  (ins GR16:$val, i16mem:$ptr),
3626                "xchg{w}\t{$val, $ptr|$ptr, $val}", 
3627                [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))]>, 
3628                 OpSize;
3629 def XCHG8rm  : I<0x86, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
3630                "xchg{b}\t{$val, $ptr|$ptr, $val}", 
3631                [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))]>;
3632
3633 def XCHG32rr : I<0x87, MRMSrcReg, (outs GR32:$dst), (ins GR32:$val, GR32:$src),
3634                  "xchg{l}\t{$val, $src|$src, $val}", []>;
3635 def XCHG16rr : I<0x87, MRMSrcReg, (outs GR16:$dst), (ins GR16:$val, GR16:$src),
3636                  "xchg{w}\t{$val, $src|$src, $val}", []>, OpSize;
3637 def XCHG8rr : I<0x86, MRMSrcReg, (outs GR8:$dst), (ins GR8:$val, GR8:$src),
3638                 "xchg{b}\t{$val, $src|$src, $val}", []>;
3639 }
3640
3641 def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src),
3642                   "xchg{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3643 def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src),
3644                   "xchg{l}\t{$src, %eax|%eax, $src}", []>;
3645
3646 // Atomic compare and swap.
3647 let Defs = [EAX, EFLAGS], Uses = [EAX] in {
3648 def LCMPXCHG32 : I<0xB1, MRMDestMem, (outs), (ins i32mem:$ptr, GR32:$swap),
3649                "lock\n\t"
3650                "cmpxchg{l}\t{$swap, $ptr|$ptr, $swap}",
3651                [(X86cas addr:$ptr, GR32:$swap, 4)]>, TB, LOCK;
3652 }
3653 let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in {
3654 def LCMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$ptr),
3655                "lock\n\t"
3656                "cmpxchg8b\t$ptr",
3657                [(X86cas8 addr:$ptr)]>, TB, LOCK;
3658 }
3659
3660 let Defs = [AX, EFLAGS], Uses = [AX] in {
3661 def LCMPXCHG16 : I<0xB1, MRMDestMem, (outs), (ins i16mem:$ptr, GR16:$swap),
3662                "lock\n\t"
3663                "cmpxchg{w}\t{$swap, $ptr|$ptr, $swap}",
3664                [(X86cas addr:$ptr, GR16:$swap, 2)]>, TB, OpSize, LOCK;
3665 }
3666 let Defs = [AL, EFLAGS], Uses = [AL] in {
3667 def LCMPXCHG8 : I<0xB0, MRMDestMem, (outs), (ins i8mem:$ptr, GR8:$swap),
3668                "lock\n\t"
3669                "cmpxchg{b}\t{$swap, $ptr|$ptr, $swap}",
3670                [(X86cas addr:$ptr, GR8:$swap, 1)]>, TB, LOCK;
3671 }
3672
3673 // Atomic exchange and add
3674 let Constraints = "$val = $dst", Defs = [EFLAGS] in {
3675 def LXADD32 : I<0xC1, MRMSrcMem, (outs GR32:$dst), (ins GR32:$val, i32mem:$ptr),
3676                "lock\n\t"
3677                "xadd{l}\t{$val, $ptr|$ptr, $val}",
3678                [(set GR32:$dst, (atomic_load_add_32 addr:$ptr, GR32:$val))]>,
3679                 TB, LOCK;
3680 def LXADD16 : I<0xC1, MRMSrcMem, (outs GR16:$dst), (ins GR16:$val, i16mem:$ptr),
3681                "lock\n\t"
3682                "xadd{w}\t{$val, $ptr|$ptr, $val}",
3683                [(set GR16:$dst, (atomic_load_add_16 addr:$ptr, GR16:$val))]>,
3684                 TB, OpSize, LOCK;
3685 def LXADD8  : I<0xC0, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
3686                "lock\n\t"
3687                "xadd{b}\t{$val, $ptr|$ptr, $val}",
3688                [(set GR8:$dst, (atomic_load_add_8 addr:$ptr, GR8:$val))]>,
3689                 TB, LOCK;
3690 }
3691
3692 def XADD8rr : I<0xC0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
3693                 "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
3694 def XADD16rr : I<0xC1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
3695                  "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3696 def XADD32rr  : I<0xC1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
3697                  "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
3698
3699 let mayLoad = 1, mayStore = 1 in {
3700 def XADD8rm   : I<0xC0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
3701                  "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
3702 def XADD16rm  : I<0xC1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
3703                  "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3704 def XADD32rm  : I<0xC1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
3705                  "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
3706 }
3707
3708 def CMPXCHG8rr : I<0xB0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
3709                    "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
3710 def CMPXCHG16rr : I<0xB1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
3711                     "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3712 def CMPXCHG32rr  : I<0xB1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
3713                      "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
3714
3715 let mayLoad = 1, mayStore = 1 in {
3716 def CMPXCHG8rm   : I<0xB0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
3717                      "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
3718 def CMPXCHG16rm  : I<0xB1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
3719                      "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3720 def CMPXCHG32rm  : I<0xB1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
3721                      "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
3722 }
3723
3724 let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in
3725 def CMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$dst),
3726                   "cmpxchg8b\t$dst", []>, TB;
3727
3728 // Optimized codegen when the non-memory output is not used.
3729 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
3730 let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in {
3731 def LOCK_ADD8mr  : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
3732                     "lock\n\t"
3733                     "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3734 def LOCK_ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
3735                     "lock\n\t"
3736                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3737 def LOCK_ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
3738                     "lock\n\t"
3739                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3740 def LOCK_ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
3741                     "lock\n\t"
3742                     "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3743 def LOCK_ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
3744                     "lock\n\t"
3745                      "add{w}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3746 def LOCK_ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
3747                     "lock\n\t"
3748                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3749 def LOCK_ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
3750                     "lock\n\t"
3751                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3752 def LOCK_ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
3753                     "lock\n\t"
3754                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3755
3756 def LOCK_INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst),
3757                     "lock\n\t"
3758                     "inc{b}\t$dst", []>, LOCK;
3759 def LOCK_INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst),
3760                     "lock\n\t"
3761                     "inc{w}\t$dst", []>, OpSize, LOCK;
3762 def LOCK_INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst),
3763                     "lock\n\t"
3764                     "inc{l}\t$dst", []>, LOCK;
3765
3766 def LOCK_SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
3767                     "lock\n\t"
3768                     "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3769 def LOCK_SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
3770                     "lock\n\t"
3771                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3772 def LOCK_SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
3773                     "lock\n\t"
3774                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3775 def LOCK_SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
3776                     "lock\n\t"
3777                     "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3778 def LOCK_SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
3779                     "lock\n\t"
3780                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3781 def LOCK_SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
3782                     "lock\n\t"
3783                      "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3784 def LOCK_SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
3785                     "lock\n\t"
3786                      "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
3787 def LOCK_SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
3788                     "lock\n\t"
3789                      "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
3790
3791 def LOCK_DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst),
3792                     "lock\n\t"
3793                     "dec{b}\t$dst", []>, LOCK;
3794 def LOCK_DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst),
3795                     "lock\n\t"
3796                     "dec{w}\t$dst", []>, OpSize, LOCK;
3797 def LOCK_DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst),
3798                     "lock\n\t"
3799                     "dec{l}\t$dst", []>, LOCK;
3800 }
3801
3802 // Atomic exchange, and, or, xor
3803 let Constraints = "$val = $dst", Defs = [EFLAGS],
3804                   usesCustomInserter = 1 in {
3805 def ATOMAND32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3806                "#ATOMAND32 PSEUDO!", 
3807                [(set GR32:$dst, (atomic_load_and_32 addr:$ptr, GR32:$val))]>;
3808 def ATOMOR32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3809                "#ATOMOR32 PSEUDO!", 
3810                [(set GR32:$dst, (atomic_load_or_32 addr:$ptr, GR32:$val))]>;
3811 def ATOMXOR32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3812                "#ATOMXOR32 PSEUDO!", 
3813                [(set GR32:$dst, (atomic_load_xor_32 addr:$ptr, GR32:$val))]>;
3814 def ATOMNAND32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3815                "#ATOMNAND32 PSEUDO!", 
3816                [(set GR32:$dst, (atomic_load_nand_32 addr:$ptr, GR32:$val))]>;
3817 def ATOMMIN32: I<0, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
3818                "#ATOMMIN32 PSEUDO!", 
3819                [(set GR32:$dst, (atomic_load_min_32 addr:$ptr, GR32:$val))]>;
3820 def ATOMMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3821                "#ATOMMAX32 PSEUDO!", 
3822                [(set GR32:$dst, (atomic_load_max_32 addr:$ptr, GR32:$val))]>;
3823 def ATOMUMIN32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3824                "#ATOMUMIN32 PSEUDO!", 
3825                [(set GR32:$dst, (atomic_load_umin_32 addr:$ptr, GR32:$val))]>;
3826 def ATOMUMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
3827                "#ATOMUMAX32 PSEUDO!", 
3828                [(set GR32:$dst, (atomic_load_umax_32 addr:$ptr, GR32:$val))]>;
3829
3830 def ATOMAND16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3831                "#ATOMAND16 PSEUDO!", 
3832                [(set GR16:$dst, (atomic_load_and_16 addr:$ptr, GR16:$val))]>;
3833 def ATOMOR16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3834                "#ATOMOR16 PSEUDO!", 
3835                [(set GR16:$dst, (atomic_load_or_16 addr:$ptr, GR16:$val))]>;
3836 def ATOMXOR16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3837                "#ATOMXOR16 PSEUDO!", 
3838                [(set GR16:$dst, (atomic_load_xor_16 addr:$ptr, GR16:$val))]>;
3839 def ATOMNAND16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3840                "#ATOMNAND16 PSEUDO!", 
3841                [(set GR16:$dst, (atomic_load_nand_16 addr:$ptr, GR16:$val))]>;
3842 def ATOMMIN16: I<0, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
3843                "#ATOMMIN16 PSEUDO!", 
3844                [(set GR16:$dst, (atomic_load_min_16 addr:$ptr, GR16:$val))]>;
3845 def ATOMMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3846                "#ATOMMAX16 PSEUDO!", 
3847                [(set GR16:$dst, (atomic_load_max_16 addr:$ptr, GR16:$val))]>;
3848 def ATOMUMIN16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3849                "#ATOMUMIN16 PSEUDO!", 
3850                [(set GR16:$dst, (atomic_load_umin_16 addr:$ptr, GR16:$val))]>;
3851 def ATOMUMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
3852                "#ATOMUMAX16 PSEUDO!", 
3853                [(set GR16:$dst, (atomic_load_umax_16 addr:$ptr, GR16:$val))]>;
3854
3855 def ATOMAND8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
3856                "#ATOMAND8 PSEUDO!", 
3857                [(set GR8:$dst, (atomic_load_and_8 addr:$ptr, GR8:$val))]>;
3858 def ATOMOR8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
3859                "#ATOMOR8 PSEUDO!", 
3860                [(set GR8:$dst, (atomic_load_or_8 addr:$ptr, GR8:$val))]>;
3861 def ATOMXOR8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
3862                "#ATOMXOR8 PSEUDO!", 
3863                [(set GR8:$dst, (atomic_load_xor_8 addr:$ptr, GR8:$val))]>;
3864 def ATOMNAND8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
3865                "#ATOMNAND8 PSEUDO!", 
3866                [(set GR8:$dst, (atomic_load_nand_8 addr:$ptr, GR8:$val))]>;
3867 }
3868
3869 let Constraints = "$val1 = $dst1, $val2 = $dst2", 
3870                   Defs = [EFLAGS, EAX, EBX, ECX, EDX],
3871                   Uses = [EAX, EBX, ECX, EDX],
3872                   mayLoad = 1, mayStore = 1,
3873                   usesCustomInserter = 1 in {
3874 def ATOMAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3875                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3876                "#ATOMAND6432 PSEUDO!", []>;
3877 def ATOMOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3878                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3879                "#ATOMOR6432 PSEUDO!", []>;
3880 def ATOMXOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3881                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3882                "#ATOMXOR6432 PSEUDO!", []>;
3883 def ATOMNAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3884                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3885                "#ATOMNAND6432 PSEUDO!", []>;
3886 def ATOMADD6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3887                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3888                "#ATOMADD6432 PSEUDO!", []>;
3889 def ATOMSUB6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3890                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3891                "#ATOMSUB6432 PSEUDO!", []>;
3892 def ATOMSWAP6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
3893                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
3894                "#ATOMSWAP6432 PSEUDO!", []>;
3895 }
3896
3897 // Lock instruction prefix
3898 def LOCK_PREFIX : I<0xF0, RawFrm, (outs),  (ins), "lock", []>;
3899
3900 // Repeat string operation instruction prefixes
3901 // These uses the DF flag in the EFLAGS register to inc or dec ECX
3902 let Defs = [ECX], Uses = [ECX,EFLAGS] in {
3903 // Repeat (used with INS, OUTS, MOVS, LODS and STOS)
3904 def REP_PREFIX : I<0xF3, RawFrm, (outs),  (ins), "rep", []>;
3905 // Repeat while not equal (used with CMPS and SCAS)
3906 def REPNE_PREFIX : I<0xF2, RawFrm, (outs),  (ins), "repne", []>;
3907 }
3908
3909
3910 // String manipulation instructions
3911
3912 def LODSB : I<0xAC, RawFrm, (outs), (ins), "lodsb", []>;
3913 def LODSW : I<0xAD, RawFrm, (outs), (ins), "lodsw", []>, OpSize;
3914 def LODSD : I<0xAD, RawFrm, (outs), (ins), "lods{l|d}", []>;
3915
3916 def OUTSB : I<0x6E, RawFrm, (outs), (ins), "outsb", []>;
3917 def OUTSW : I<0x6F, RawFrm, (outs), (ins), "outsw", []>, OpSize;
3918 def OUTSD : I<0x6F, RawFrm, (outs), (ins), "outs{l|d}", []>;
3919
3920
3921 // Flag instructions
3922 def CLC : I<0xF8, RawFrm, (outs), (ins), "clc", []>;
3923 def STC : I<0xF9, RawFrm, (outs), (ins), "stc", []>;
3924 def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
3925 def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
3926 def CLD : I<0xFC, RawFrm, (outs), (ins), "cld", []>;
3927 def STD : I<0xFD, RawFrm, (outs), (ins), "std", []>;
3928 def CMC : I<0xF5, RawFrm, (outs), (ins), "cmc", []>;
3929
3930 def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
3931
3932 // Table lookup instructions
3933 def XLAT : I<0xD7, RawFrm, (outs), (ins), "xlatb", []>;
3934
3935
3936
3937 //===----------------------------------------------------------------------===//
3938 // Subsystems.
3939 //===----------------------------------------------------------------------===//
3940
3941 // Floating Point Stack Support
3942 include "X86InstrFPStack.td"
3943
3944 // X86-64 Support
3945 include "X86Instr64bit.td"
3946
3947 include "X86InstrControl.td"
3948
3949 // SIMD support (SSE, MMX and AVX)
3950 include "X86InstrFragmentsSIMD.td"
3951
3952 // FMA - Fused Multiply-Add support (requires FMA)
3953 include "X86InstrFMA.td"
3954
3955 // SSE, MMX and 3DNow! vector support.
3956 include "X86InstrSSE.td"
3957 include "X86InstrMMX.td"
3958 include "X86Instr3DNow.td"
3959
3960 include "X86InstrVMX.td"
3961
3962 // System instructions.
3963 include "X86InstrSystem.td"
3964
3965 // Compiler Pseudo Instructions and Pat Patterns
3966 include "X86InstrCompiler.td"
3967