092bb36f7a69d65832b32018df913c1fb5ff95ce
[oota-llvm.git] / lib / Target / X86 / X86InstrInfo.td
1 //===----------------------------------------------------------------------===//
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_X86SegmentBaseAddress : SDTypeProfile<1, 1, [SDTCisPtrTy<0>]>;
78
79 def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
80
81 def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
82
83 def X86bsf     : SDNode<"X86ISD::BSF",      SDTUnaryArithWithFlags>;
84 def X86bsr     : SDNode<"X86ISD::BSR",      SDTUnaryArithWithFlags>;
85 def X86shld    : SDNode<"X86ISD::SHLD",     SDTIntShiftDOp>;
86 def X86shrd    : SDNode<"X86ISD::SHRD",     SDTIntShiftDOp>;
87
88 def X86cmp     : SDNode<"X86ISD::CMP" ,     SDTX86CmpTest>;
89 def X86bt      : SDNode<"X86ISD::BT",       SDTX86CmpTest>;
90
91 def X86cmov    : SDNode<"X86ISD::CMOV",     SDTX86Cmov>;
92 def X86brcond  : SDNode<"X86ISD::BRCOND",   SDTX86BrCond,
93                         [SDNPHasChain]>;
94 def X86setcc   : SDNode<"X86ISD::SETCC",    SDTX86SetCC>;
95 def X86setcc_c : SDNode<"X86ISD::SETCC_CARRY", SDTX86SetCC_C>;
96
97 def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas,
98                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
99                          SDNPMayLoad]>;
100 def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86cas8,
101                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
102                          SDNPMayLoad]>;
103 def X86AtomAdd64 : SDNode<"X86ISD::ATOMADD64_DAG", SDTX86atomicBinary,
104                         [SDNPHasChain, SDNPMayStore, 
105                          SDNPMayLoad, SDNPMemOperand]>;
106 def X86AtomSub64 : SDNode<"X86ISD::ATOMSUB64_DAG", SDTX86atomicBinary,
107                         [SDNPHasChain, SDNPMayStore, 
108                          SDNPMayLoad, SDNPMemOperand]>;
109 def X86AtomOr64 : SDNode<"X86ISD::ATOMOR64_DAG", SDTX86atomicBinary,
110                         [SDNPHasChain, SDNPMayStore, 
111                          SDNPMayLoad, SDNPMemOperand]>;
112 def X86AtomXor64 : SDNode<"X86ISD::ATOMXOR64_DAG", SDTX86atomicBinary,
113                         [SDNPHasChain, SDNPMayStore, 
114                          SDNPMayLoad, SDNPMemOperand]>;
115 def X86AtomAnd64 : SDNode<"X86ISD::ATOMAND64_DAG", SDTX86atomicBinary,
116                         [SDNPHasChain, SDNPMayStore, 
117                          SDNPMayLoad, SDNPMemOperand]>;
118 def X86AtomNand64 : SDNode<"X86ISD::ATOMNAND64_DAG", SDTX86atomicBinary,
119                         [SDNPHasChain, SDNPMayStore, 
120                          SDNPMayLoad, SDNPMemOperand]>;
121 def X86AtomSwap64 : SDNode<"X86ISD::ATOMSWAP64_DAG", SDTX86atomicBinary,
122                         [SDNPHasChain, SDNPMayStore, 
123                          SDNPMayLoad, SDNPMemOperand]>;
124 def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
125                         [SDNPHasChain, SDNPOptInFlag, SDNPVariadic]>;
126
127 def X86vastart_save_xmm_regs :
128                  SDNode<"X86ISD::VASTART_SAVE_XMM_REGS",
129                         SDT_X86VASTART_SAVE_XMM_REGS,
130                         [SDNPHasChain, SDNPVariadic]>;
131
132 def X86callseq_start :
133                  SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
134                         [SDNPHasChain, SDNPOutFlag]>;
135 def X86callseq_end :
136                  SDNode<"ISD::CALLSEQ_END",   SDT_X86CallSeqEnd,
137                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;       
138
139 def X86call    : SDNode<"X86ISD::CALL",     SDT_X86Call,
140                         [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag,
141                          SDNPVariadic]>;
142
143 def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
144                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore]>;
145 def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
146                         [SDNPHasChain, SDNPInFlag, SDNPOutFlag, SDNPMayStore,
147                          SDNPMayLoad]>;
148
149 def X86rdtsc   : SDNode<"X86ISD::RDTSC_DAG", SDTX86Void,
150                         [SDNPHasChain, SDNPOutFlag, SDNPSideEffect]>;
151
152 def X86Wrapper    : SDNode<"X86ISD::Wrapper",     SDTX86Wrapper>;
153 def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP",  SDTX86Wrapper>;
154
155 def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR,
156                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
157 def X86SegmentBaseAddress : SDNode<"X86ISD::SegmentBaseAddress",
158                                  SDT_X86SegmentBaseAddress, []>;
159
160 def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET,
161                         [SDNPHasChain]>;
162
163 def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET, 
164                         [SDNPHasChain,  SDNPOptInFlag, SDNPVariadic]>;
165
166 def X86add_flag  : SDNode<"X86ISD::ADD",  SDTBinaryArithWithFlags,
167                           [SDNPCommutative]>;
168 def X86sub_flag  : SDNode<"X86ISD::SUB",  SDTBinaryArithWithFlags>;
169 def X86smul_flag : SDNode<"X86ISD::SMUL", SDTBinaryArithWithFlags,
170                           [SDNPCommutative]>;
171 def X86umul_flag : SDNode<"X86ISD::UMUL", SDTUnaryArithWithFlags,
172                           [SDNPCommutative]>;
173                           
174 def X86inc_flag  : SDNode<"X86ISD::INC",  SDTUnaryArithWithFlags>;
175 def X86dec_flag  : SDNode<"X86ISD::DEC",  SDTUnaryArithWithFlags>;
176 def X86or_flag   : SDNode<"X86ISD::OR",   SDTBinaryArithWithFlags,
177                           [SDNPCommutative]>;
178 def X86xor_flag  : SDNode<"X86ISD::XOR",  SDTBinaryArithWithFlags,
179                           [SDNPCommutative]>;
180 def X86and_flag  : SDNode<"X86ISD::AND",  SDTBinaryArithWithFlags,
181                           [SDNPCommutative]>;
182
183 def X86mul_imm : SDNode<"X86ISD::MUL_IMM", SDTIntBinOp>;
184
185 def X86MingwAlloca : SDNode<"X86ISD::MINGW_ALLOCA", SDTX86Void,
186                             [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
187                             
188 def X86TLSCall : SDNode<"X86ISD::TLSCALL", SDT_X86TLSCALL,
189                         []>;
190
191 //===----------------------------------------------------------------------===//
192 // X86 Operand Definitions.
193 //
194
195 // A version of ptr_rc which excludes SP, ESP, and RSP. This is used for
196 // the index operand of an address, to conform to x86 encoding restrictions.
197 def ptr_rc_nosp : PointerLikeRegClass<1>;
198
199 // *mem - Operand definitions for the funky X86 addressing mode operands.
200 //
201 def X86MemAsmOperand : AsmOperandClass {
202   let Name = "Mem";
203   let SuperClasses = [];
204 }
205 def X86AbsMemAsmOperand : AsmOperandClass {
206   let Name = "AbsMem";
207   let SuperClasses = [X86MemAsmOperand];
208 }
209 class X86MemOperand<string printMethod> : Operand<iPTR> {
210   let PrintMethod = printMethod;
211   let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
212   let ParserMatchClass = X86MemAsmOperand;
213 }
214
215 def opaque32mem : X86MemOperand<"printopaquemem">;
216 def opaque48mem : X86MemOperand<"printopaquemem">;
217 def opaque80mem : X86MemOperand<"printopaquemem">;
218 def opaque512mem : X86MemOperand<"printopaquemem">;
219
220 def i8mem   : X86MemOperand<"printi8mem">;
221 def i16mem  : X86MemOperand<"printi16mem">;
222 def i32mem  : X86MemOperand<"printi32mem">;
223 def i64mem  : X86MemOperand<"printi64mem">;
224 def i128mem : X86MemOperand<"printi128mem">;
225 //def i256mem : X86MemOperand<"printi256mem">;
226 def f32mem  : X86MemOperand<"printf32mem">;
227 def f64mem  : X86MemOperand<"printf64mem">;
228 def f80mem  : X86MemOperand<"printf80mem">;
229 def f128mem : X86MemOperand<"printf128mem">;
230 def f256mem : X86MemOperand<"printf256mem">;
231
232 // A version of i8mem for use on x86-64 that uses GR64_NOREX instead of
233 // plain GR64, so that it doesn't potentially require a REX prefix.
234 def i8mem_NOREX : Operand<i64> {
235   let PrintMethod = "printi8mem";
236   let MIOperandInfo = (ops GR64_NOREX, i8imm, GR64_NOREX_NOSP, i32imm, i8imm);
237   let ParserMatchClass = X86MemAsmOperand;
238 }
239
240 // Special i32mem for addresses of load folding tail calls. These are not
241 // allowed to use callee-saved registers since they must be scheduled
242 // after callee-saved register are popped.
243 def i32mem_TC : Operand<i32> {
244   let PrintMethod = "printi32mem";
245   let MIOperandInfo = (ops GR32_TC, i8imm, GR32_TC, i32imm, i8imm);
246   let ParserMatchClass = X86MemAsmOperand;
247 }
248
249
250 let ParserMatchClass = X86AbsMemAsmOperand,
251     PrintMethod = "print_pcrel_imm" in {
252 def i32imm_pcrel : Operand<i32>;
253 def i16imm_pcrel : Operand<i16>;
254
255 def offset8 : Operand<i64>;
256 def offset16 : Operand<i64>;
257 def offset32 : Operand<i64>;
258 def offset64 : Operand<i64>;
259
260 // Branch targets have OtherVT type and print as pc-relative values.
261 def brtarget : Operand<OtherVT>;
262 def brtarget8 : Operand<OtherVT>;
263
264 }
265
266 def SSECC : Operand<i8> {
267   let PrintMethod = "printSSECC";
268 }
269
270 class ImmSExtAsmOperandClass : AsmOperandClass {
271   let SuperClasses = [ImmAsmOperand];
272   let RenderMethod = "addImmOperands";
273 }
274
275 // Sign-extended immediate classes. We don't need to define the full lattice
276 // here because there is no instruction with an ambiguity between ImmSExti64i32
277 // and ImmSExti32i8.
278 //
279 // The strange ranges come from the fact that the assembler always works with
280 // 64-bit immediates, but for a 16-bit target value we want to accept both "-1"
281 // (which will be a -1ULL), and "0xFF" (-1 in 16-bits).
282
283 // [0, 0x7FFFFFFF]                                            |
284 //   [0xFFFFFFFF80000000, 0xFFFFFFFFFFFFFFFF]
285 def ImmSExti64i32AsmOperand : ImmSExtAsmOperandClass {
286   let Name = "ImmSExti64i32";
287 }
288
289 // [0, 0x0000007F] | [0x000000000000FF80, 0x000000000000FFFF] |
290 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
291 def ImmSExti16i8AsmOperand : ImmSExtAsmOperandClass {
292   let Name = "ImmSExti16i8";
293   let SuperClasses = [ImmSExti64i32AsmOperand];
294 }
295
296 // [0, 0x0000007F] | [0x00000000FFFFFF80, 0x00000000FFFFFFFF] |
297 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
298 def ImmSExti32i8AsmOperand : ImmSExtAsmOperandClass {
299   let Name = "ImmSExti32i8";
300 }
301
302 // [0, 0x0000007F]                                            |
303 //   [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
304 def ImmSExti64i8AsmOperand : ImmSExtAsmOperandClass {
305   let Name = "ImmSExti64i8";
306   let SuperClasses = [ImmSExti16i8AsmOperand, ImmSExti32i8AsmOperand,
307                       ImmSExti64i32AsmOperand];
308 }
309
310 // A couple of more descriptive operand definitions.
311 // 16-bits but only 8 bits are significant.
312 def i16i8imm  : Operand<i16> {
313   let ParserMatchClass = ImmSExti16i8AsmOperand;
314 }
315 // 32-bits but only 8 bits are significant.
316 def i32i8imm  : Operand<i32> {
317   let ParserMatchClass = ImmSExti32i8AsmOperand;
318 }
319
320 //===----------------------------------------------------------------------===//
321 // X86 Complex Pattern Definitions.
322 //
323
324 // Define X86 specific addressing mode.
325 def addr      : ComplexPattern<iPTR, 5, "SelectAddr", [], []>;
326 def lea32addr : ComplexPattern<i32, 5, "SelectLEAAddr",
327                                [add, sub, mul, X86mul_imm, shl, or, frameindex],
328                                []>;
329 def tls32addr : ComplexPattern<i32, 5, "SelectTLSADDRAddr",
330                                [tglobaltlsaddr], []>;
331
332 //===----------------------------------------------------------------------===//
333 // X86 Instruction Predicate Definitions.
334 def HasCMov      : Predicate<"Subtarget->hasCMov()">;
335 def NoCMov       : Predicate<"!Subtarget->hasCMov()">;
336 def HasMMX       : Predicate<"Subtarget->hasMMX()">;
337 def HasSSE1      : Predicate<"Subtarget->hasSSE1()">;
338 def HasSSE2      : Predicate<"Subtarget->hasSSE2()">;
339 def HasSSE3      : Predicate<"Subtarget->hasSSE3()">;
340 def HasSSSE3     : Predicate<"Subtarget->hasSSSE3()">;
341 def HasSSE41     : Predicate<"Subtarget->hasSSE41()">;
342 def HasSSE42     : Predicate<"Subtarget->hasSSE42()">;
343 def HasSSE4A     : Predicate<"Subtarget->hasSSE4A()">;
344 def HasAVX       : Predicate<"Subtarget->hasAVX()">;
345 def HasFMA3      : Predicate<"Subtarget->hasFMA3()">;
346 def HasFMA4      : Predicate<"Subtarget->hasFMA4()">;
347 def FPStackf32   : Predicate<"!Subtarget->hasSSE1()">;
348 def FPStackf64   : Predicate<"!Subtarget->hasSSE2()">;
349 def In32BitMode  : Predicate<"!Subtarget->is64Bit()">;
350 def In64BitMode  : Predicate<"Subtarget->is64Bit()">;
351 def IsWin64      : Predicate<"Subtarget->isTargetWin64()">;
352 def NotWin64     : Predicate<"!Subtarget->isTargetWin64()">;
353 def SmallCode    : Predicate<"TM.getCodeModel() == CodeModel::Small">;
354 def KernelCode   : Predicate<"TM.getCodeModel() == CodeModel::Kernel">;
355 def FarData      : Predicate<"TM.getCodeModel() != CodeModel::Small &&"
356                              "TM.getCodeModel() != CodeModel::Kernel">;
357 def NearData     : Predicate<"TM.getCodeModel() == CodeModel::Small ||"
358                              "TM.getCodeModel() == CodeModel::Kernel">;
359 def IsStatic     : Predicate<"TM.getRelocationModel() == Reloc::Static">;
360 def IsNotPIC     : Predicate<"TM.getRelocationModel() != Reloc::PIC_">;
361 def OptForSize   : Predicate<"OptForSize">;
362 def OptForSpeed  : Predicate<"!OptForSize">;
363 def FastBTMem    : Predicate<"!Subtarget->isBTMemSlow()">;
364 def CallImmAddr  : Predicate<"Subtarget->IsLegalToCallImmediateAddr(TM)">;
365 def HasAES       : Predicate<"Subtarget->hasAES()">;
366
367 //===----------------------------------------------------------------------===//
368 // X86 Instruction Format Definitions.
369 //
370
371 include "X86InstrFormats.td"
372
373 //===----------------------------------------------------------------------===//
374 // Pattern fragments...
375 //
376
377 // X86 specific condition code. These correspond to CondCode in
378 // X86InstrInfo.h. They must be kept in synch.
379 def X86_COND_A   : PatLeaf<(i8 0)>;  // alt. COND_NBE
380 def X86_COND_AE  : PatLeaf<(i8 1)>;  // alt. COND_NC
381 def X86_COND_B   : PatLeaf<(i8 2)>;  // alt. COND_C
382 def X86_COND_BE  : PatLeaf<(i8 3)>;  // alt. COND_NA
383 def X86_COND_E   : PatLeaf<(i8 4)>;  // alt. COND_Z
384 def X86_COND_G   : PatLeaf<(i8 5)>;  // alt. COND_NLE
385 def X86_COND_GE  : PatLeaf<(i8 6)>;  // alt. COND_NL
386 def X86_COND_L   : PatLeaf<(i8 7)>;  // alt. COND_NGE
387 def X86_COND_LE  : PatLeaf<(i8 8)>;  // alt. COND_NG
388 def X86_COND_NE  : PatLeaf<(i8 9)>;  // alt. COND_NZ
389 def X86_COND_NO  : PatLeaf<(i8 10)>;
390 def X86_COND_NP  : PatLeaf<(i8 11)>; // alt. COND_PO
391 def X86_COND_NS  : PatLeaf<(i8 12)>;
392 def X86_COND_O   : PatLeaf<(i8 13)>;
393 def X86_COND_P   : PatLeaf<(i8 14)>; // alt. COND_PE
394 def X86_COND_S   : PatLeaf<(i8 15)>;
395
396 def immSext8 : PatLeaf<(imm), [{
397   return N->getSExtValue() == (int8_t)N->getSExtValue();
398 }]>;
399
400 def i16immSExt8  : PatLeaf<(i16 immSext8)>;
401 def i32immSExt8  : PatLeaf<(i32 immSext8)>;
402
403 /// Load patterns: these constraint the match to the right address space.
404 def dsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
405   if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
406     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
407       if (PT->getAddressSpace() > 255)
408         return false;
409   return true;
410 }]>;
411
412 def gsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
413   if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
414     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
415       return PT->getAddressSpace() == 256;
416   return false;
417 }]>;
418
419 def fsload : PatFrag<(ops node:$ptr), (load node:$ptr), [{
420   if (const Value *Src = cast<LoadSDNode>(N)->getSrcValue())
421     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
422       return PT->getAddressSpace() == 257;
423   return false;
424 }]>;
425
426
427 // Helper fragments for loads.
428 // It's always safe to treat a anyext i16 load as a i32 load if the i16 is
429 // known to be 32-bit aligned or better. Ditto for i8 to i16.
430 def loadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{
431   LoadSDNode *LD = cast<LoadSDNode>(N);
432   if (const Value *Src = LD->getSrcValue())
433     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
434       if (PT->getAddressSpace() > 255)
435         return false;
436   ISD::LoadExtType ExtType = LD->getExtensionType();
437   if (ExtType == ISD::NON_EXTLOAD)
438     return true;
439   if (ExtType == ISD::EXTLOAD)
440     return LD->getAlignment() >= 2 && !LD->isVolatile();
441   return false;
442 }]>;
443
444 def loadi16_anyext : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)),[{
445   LoadSDNode *LD = cast<LoadSDNode>(N);
446   if (const Value *Src = LD->getSrcValue())
447     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
448       if (PT->getAddressSpace() > 255)
449         return false;
450   ISD::LoadExtType ExtType = LD->getExtensionType();
451   if (ExtType == ISD::EXTLOAD)
452     return LD->getAlignment() >= 2 && !LD->isVolatile();
453   return false;
454 }]>;
455
456 def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
457   LoadSDNode *LD = cast<LoadSDNode>(N);
458   if (const Value *Src = LD->getSrcValue())
459     if (const PointerType *PT = dyn_cast<PointerType>(Src->getType()))
460       if (PT->getAddressSpace() > 255)
461         return false;
462   ISD::LoadExtType ExtType = LD->getExtensionType();
463   if (ExtType == ISD::NON_EXTLOAD)
464     return true;
465   if (ExtType == ISD::EXTLOAD)
466     return LD->getAlignment() >= 4 && !LD->isVolatile();
467   return false;
468 }]>;
469
470 def loadi8  : PatFrag<(ops node:$ptr), (i8  (dsload node:$ptr))>;
471 def loadi64 : PatFrag<(ops node:$ptr), (i64 (dsload node:$ptr))>;
472 def loadf32 : PatFrag<(ops node:$ptr), (f32 (dsload node:$ptr))>;
473 def loadf64 : PatFrag<(ops node:$ptr), (f64 (dsload node:$ptr))>;
474 def loadf80 : PatFrag<(ops node:$ptr), (f80 (dsload node:$ptr))>;
475
476 def sextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
477 def sextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
478 def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
479
480 def zextloadi8i1   : PatFrag<(ops node:$ptr), (i8  (zextloadi1 node:$ptr))>;
481 def zextloadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
482 def zextloadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
483 def zextloadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
484 def zextloadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
485 def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
486
487 def extloadi8i1    : PatFrag<(ops node:$ptr), (i8  (extloadi1 node:$ptr))>;
488 def extloadi16i1   : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
489 def extloadi32i1   : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
490 def extloadi16i8   : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
491 def extloadi32i8   : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
492 def extloadi32i16  : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
493
494
495 // An 'and' node with a single use.
496 def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
497   return N->hasOneUse();
498 }]>;
499 // An 'srl' node with a single use.
500 def srl_su : PatFrag<(ops node:$lhs, node:$rhs), (srl node:$lhs, node:$rhs), [{
501   return N->hasOneUse();
502 }]>;
503 // An 'trunc' node with a single use.
504 def trunc_su : PatFrag<(ops node:$src), (trunc node:$src), [{
505   return N->hasOneUse();
506 }]>;
507
508 // Treat an 'or' node is as an 'add' if the or'ed bits are known to be zero.
509 def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
510   if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1)))
511     return CurDAG->MaskedValueIsZero(N->getOperand(0), CN->getAPIntValue());
512
513   unsigned BitWidth = N->getValueType(0).getScalarType().getSizeInBits();
514   APInt Mask = APInt::getAllOnesValue(BitWidth);
515   APInt KnownZero0, KnownOne0;
516   CurDAG->ComputeMaskedBits(N->getOperand(0), Mask, KnownZero0, KnownOne0, 0);
517   APInt KnownZero1, KnownOne1;
518   CurDAG->ComputeMaskedBits(N->getOperand(1), Mask, KnownZero1, KnownOne1, 0);
519   return (~KnownZero0 & ~KnownZero1) == 0;
520 }]>;
521
522 //===----------------------------------------------------------------------===//
523 // Instruction list...
524 //
525
526 // ADJCALLSTACKDOWN/UP implicitly use/def ESP because they may be expanded into
527 // a stack adjustment and the codegen must know that they may modify the stack
528 // pointer before prolog-epilog rewriting occurs.
529 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
530 // sub / add which can clobber EFLAGS.
531 let Defs = [ESP, EFLAGS], Uses = [ESP] in {
532 def ADJCALLSTACKDOWN32 : I<0, Pseudo, (outs), (ins i32imm:$amt),
533                            "#ADJCALLSTACKDOWN",
534                            [(X86callseq_start timm:$amt)]>,
535                           Requires<[In32BitMode]>;
536 def ADJCALLSTACKUP32   : I<0, Pseudo, (outs), (ins i32imm:$amt1, i32imm:$amt2),
537                            "#ADJCALLSTACKUP",
538                            [(X86callseq_end timm:$amt1, timm:$amt2)]>,
539                           Requires<[In32BitMode]>;
540 }
541
542 // x86-64 va_start lowering magic.
543 let usesCustomInserter = 1 in {
544 def VASTART_SAVE_XMM_REGS : I<0, Pseudo,
545                               (outs),
546                               (ins GR8:$al,
547                                    i64imm:$regsavefi, i64imm:$offset,
548                                    variable_ops),
549                               "#VASTART_SAVE_XMM_REGS $al, $regsavefi, $offset",
550                               [(X86vastart_save_xmm_regs GR8:$al,
551                                                          imm:$regsavefi,
552                                                          imm:$offset)]>;
553
554 // Dynamic stack allocation yields _alloca call for Cygwin/Mingw targets.  Calls
555 // to _alloca is needed to probe the stack when allocating more than 4k bytes in
556 // one go. Touching the stack at 4K increments is necessary to ensure that the
557 // guard pages used by the OS virtual memory manager are allocated in correct
558 // sequence.
559 // The main point of having separate instruction are extra unmodelled effects
560 // (compared to ordinary calls) like stack pointer change.
561
562 def MINGW_ALLOCA : I<0, Pseudo, (outs), (ins),
563                      "# dynamic stack allocation",
564                      [(X86MingwAlloca)]>;
565 }
566
567 // Nop
568 let neverHasSideEffects = 1 in {
569   def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", []>;
570   def NOOPW : I<0x1f, MRM0m, (outs), (ins i16mem:$zero),
571                 "nop{w}\t$zero", []>, TB, OpSize;
572   def NOOPL : I<0x1f, MRM0m, (outs), (ins i32mem:$zero),
573                 "nop{l}\t$zero", []>, TB;
574 }
575
576 // Trap
577 def INTO : I<0xce, RawFrm, (outs), (ins), "into", []>;
578 def INT3 : I<0xcc, RawFrm, (outs), (ins), "int3", []>;
579 // FIXME: need to make sure that "int $3" matches int3
580 def INT : Ii8<0xcd, RawFrm, (outs), (ins i8imm:$trap), "int\t$trap", []>;
581 def IRET16 : I<0xcf, RawFrm, (outs), (ins), "iret{w}", []>, OpSize;
582 def IRET32 : I<0xcf, RawFrm, (outs), (ins), "iret{l}", []>;
583
584 // PIC base construction.  This expands to code that looks like this:
585 //     call  $next_inst
586 //     popl %destreg"
587 let neverHasSideEffects = 1, isNotDuplicable = 1, Uses = [ESP] in
588   def MOVPC32r : Ii32<0xE8, Pseudo, (outs GR32:$reg), (ins i32imm:$label),
589                       "", []>;
590
591 //===----------------------------------------------------------------------===//
592 //  Control Flow Instructions.
593 //
594
595 // Return instructions.
596 let isTerminator = 1, isReturn = 1, isBarrier = 1,
597     hasCtrlDep = 1, FPForm = SpecialFP in {
598   def RET    : I   <0xC3, RawFrm, (outs), (ins variable_ops),
599                     "ret",
600                     [(X86retflag 0)]>;
601   def RETI   : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
602                     "ret\t$amt",
603                     [(X86retflag timm:$amt)]>;
604   def LRET   : I   <0xCB, RawFrm, (outs), (ins),
605                     "lret", []>;
606   def LRETI  : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
607                     "lret\t$amt", []>;
608 }
609
610 // Unconditional branches.
611 let isBarrier = 1, isBranch = 1, isTerminator = 1 in {
612   def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
613                         "jmp\t$dst", [(br bb:$dst)]>;
614   def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
615                        "jmp\t$dst", []>;
616 }
617
618 // Conditional Branches.
619 let isBranch = 1, isTerminator = 1, Uses = [EFLAGS] in {
620   multiclass ICBr<bits<8> opc1, bits<8> opc4, string asm, PatFrag Cond> {
621     def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm, []>;
622     def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
623                        [(X86brcond bb:$dst, Cond, EFLAGS)]>, TB;
624   }
625 }
626
627 defm JO  : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
628 defm JNO : ICBr<0x71, 0x81, "jno\t$dst" , X86_COND_NO>;
629 defm JB  : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
630 defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
631 defm JE  : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
632 defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
633 defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
634 defm JA  : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
635 defm JS  : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
636 defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
637 defm JP  : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
638 defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
639 defm JL  : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
640 defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
641 defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
642 defm JG  : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
643
644 // FIXME: What about the CX/RCX versions of this instruction?
645 let Uses = [ECX], isBranch = 1, isTerminator = 1 in
646   def JCXZ8 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
647                        "jcxz\t$dst", []>;
648
649
650 // Indirect branches
651 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
652   def JMP32r     : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
653                      [(brind GR32:$dst)]>;
654   def JMP32m     : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
655                      [(brind (loadi32 addr:$dst))]>;
656                      
657   def FARJMP16i  : Iseg16<0xEA, RawFrm, (outs), 
658                           (ins i16imm:$seg, i16imm:$off),
659                           "ljmp{w}\t$seg, $off", []>, OpSize;
660   def FARJMP32i  : Iseg32<0xEA, RawFrm, (outs),
661                           (ins i16imm:$seg, i32imm:$off),
662                           "ljmp{l}\t$seg, $off", []>;                     
663
664   def FARJMP16m  : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst), 
665                      "ljmp{w}\t{*}$dst", []>, OpSize;
666   def FARJMP32m  : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
667                      "ljmp{l}\t{*}$dst", []>;
668 }
669
670
671 // Loop instructions
672
673 def LOOP   : I<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>;
674 def LOOPE  : I<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>;
675 def LOOPNE : I<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>;
676
677 //===----------------------------------------------------------------------===//
678 //  Call Instructions...
679 //
680 let isCall = 1 in
681   // All calls clobber the non-callee saved registers. ESP is marked as
682   // a use to prevent stack-pointer assignments that appear immediately
683   // before calls from potentially appearing dead. Uses for argument
684   // registers are added manually.
685   let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
686               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
687               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
688               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
689       Uses = [ESP] in {
690     def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
691                            (outs), (ins i32imm_pcrel:$dst,variable_ops),
692                            "call\t$dst", []>;
693     def CALL32r     : I<0xFF, MRM2r, (outs), (ins GR32:$dst, variable_ops),
694                         "call\t{*}$dst", [(X86call GR32:$dst)]>;
695     def CALL32m     : I<0xFF, MRM2m, (outs), (ins i32mem:$dst, variable_ops),
696                         "call\t{*}$dst", [(X86call (loadi32 addr:$dst))]>;
697   
698     def FARCALL16i  : Iseg16<0x9A, RawFrm, (outs), 
699                              (ins i16imm:$seg, i16imm:$off),
700                              "lcall{w}\t$seg, $off", []>, OpSize;
701     def FARCALL32i  : Iseg32<0x9A, RawFrm, (outs),
702                              (ins i16imm:$seg, i32imm:$off),
703                              "lcall{l}\t$seg, $off", []>;
704                              
705     def FARCALL16m  : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
706                         "lcall{w}\t{*}$dst", []>, OpSize;
707     def FARCALL32m  : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
708                         "lcall{l}\t{*}$dst", []>;
709
710     // callw for 16 bit code for the assembler.
711     let isAsmParserOnly = 1 in
712       def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
713                        (outs), (ins i16imm_pcrel:$dst, variable_ops),
714                        "callw\t$dst", []>, OpSize;
715   }
716
717 // Constructing a stack frame.
718
719 def ENTER : I<0xC8, RawFrm, (outs), (ins i16imm:$len, i8imm:$lvl),
720               "enter\t$len, $lvl", []>;
721
722 // Tail call stuff.
723
724 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in
725   let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
726               MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
727               XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
728               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
729       Uses = [ESP] in {
730   def TCRETURNdi : I<0, Pseudo, (outs), 
731                      (ins i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
732                    "#TC_RETURN $dst $offset", []>;
733   def TCRETURNri : I<0, Pseudo, (outs), 
734                      (ins GR32_TC:$dst, i32imm:$offset, variable_ops),
735                      "#TC_RETURN $dst $offset", []>;
736   let mayLoad = 1 in
737   def TCRETURNmi : I<0, Pseudo, (outs), 
738                      (ins i32mem_TC:$dst, i32imm:$offset, variable_ops),
739                      "#TC_RETURN $dst $offset", []>;
740
741   // FIXME: The should be pseudo instructions that are lowered when going to
742   // mcinst.
743   def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
744                            (ins i32imm_pcrel:$dst, variable_ops),
745                  "jmp\t$dst  # TAILCALL",
746                  []>;
747   def TAILJMPr : I<0xFF, MRM4r, (outs), (ins GR32_TC:$dst, variable_ops), 
748                    "", []>;  // FIXME: Remove encoding when JIT is dead.
749   let mayLoad = 1 in
750   def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst, variable_ops),
751                    "jmp{l}\t{*}$dst  # TAILCALL", []>;
752 }
753
754 //===----------------------------------------------------------------------===//
755 //  Miscellaneous Instructions...
756 //
757 let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, neverHasSideEffects=1 in
758 def LEAVE    : I<0xC9, RawFrm,
759                  (outs), (ins), "leave", []>;
760
761 def POPCNT16rr : I<0xB8, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
762                    "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
763 let mayLoad = 1 in
764 def POPCNT16rm : I<0xB8, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
765                    "popcnt{w}\t{$src, $dst|$dst, $src}", []>, OpSize, XS;
766 def POPCNT32rr : I<0xB8, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
767                    "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
768 let mayLoad = 1 in
769 def POPCNT32rm : I<0xB8, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
770                    "popcnt{l}\t{$src, $dst|$dst, $src}", []>, XS;
771
772 let Defs = [ESP], Uses = [ESP], neverHasSideEffects=1 in {
773 let mayLoad = 1 in {
774 def POP16r  : I<0x58, AddRegFrm, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
775   OpSize;
776 def POP32r  : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
777 def POP16rmr: I<0x8F, MRM0r, (outs GR16:$reg), (ins), "pop{w}\t$reg", []>,
778   OpSize;
779 def POP16rmm: I<0x8F, MRM0m, (outs i16mem:$dst), (ins), "pop{w}\t$dst", []>,
780   OpSize;
781 def POP32rmr: I<0x8F, MRM0r, (outs GR32:$reg), (ins), "pop{l}\t$reg", []>;
782 def POP32rmm: I<0x8F, MRM0m, (outs i32mem:$dst), (ins), "pop{l}\t$dst", []>;
783 }
784
785 let mayStore = 1 in {
786 def PUSH16r  : I<0x50, AddRegFrm, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
787   OpSize;
788 def PUSH32r  : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
789 def PUSH16rmr: I<0xFF, MRM6r, (outs), (ins GR16:$reg), "push{w}\t$reg",[]>,
790   OpSize;
791 def PUSH16rmm: I<0xFF, MRM6m, (outs), (ins i16mem:$src), "push{w}\t$src",[]>,
792   OpSize;
793 def PUSH32rmr: I<0xFF, MRM6r, (outs), (ins GR32:$reg), "push{l}\t$reg",[]>;
794 def PUSH32rmm: I<0xFF, MRM6m, (outs), (ins i32mem:$src), "push{l}\t$src",[]>;
795 }
796 }
797
798 let Defs = [ESP], Uses = [ESP], neverHasSideEffects = 1, mayStore = 1 in {
799 def PUSHi8   : Ii8<0x6a, RawFrm, (outs), (ins i32i8imm:$imm), 
800                       "push{l}\t$imm", []>;
801 def PUSHi16  : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm), 
802                       "push{w}\t$imm", []>, OpSize;
803 def PUSHi32  : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm), 
804                       "push{l}\t$imm", []>;
805 }
806
807 let Defs = [ESP, EFLAGS], Uses = [ESP], mayLoad = 1, neverHasSideEffects=1 in {
808 def POPF16   : I<0x9D, RawFrm, (outs), (ins), "popf{w}", []>, OpSize;
809 def POPF32   : I<0x9D, RawFrm, (outs), (ins), "popf{l|d}", []>,
810                Requires<[In32BitMode]>;
811 }
812 let Defs = [ESP], Uses = [ESP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in {
813 def PUSHF16  : I<0x9C, RawFrm, (outs), (ins), "pushf{w}", []>, OpSize;
814 def PUSHF32  : I<0x9C, RawFrm, (outs), (ins), "pushf{l|d}", []>,
815                Requires<[In32BitMode]>;
816 }
817
818 let Defs = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP], Uses = [ESP],
819     mayLoad=1, neverHasSideEffects=1 in {
820 def POPA32   : I<0x61, RawFrm, (outs), (ins), "popa{l}", []>,
821                Requires<[In32BitMode]>;
822 }
823 let Defs = [ESP], Uses = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP],
824     mayStore=1, neverHasSideEffects=1 in {
825 def PUSHA32  : I<0x60, RawFrm, (outs), (ins), "pusha{l}", []>,
826                Requires<[In32BitMode]>;
827 }
828
829 let Uses = [EFLAGS], Constraints = "$src = $dst" in     // GR32 = bswap GR32
830   def BSWAP32r : I<0xC8, AddRegFrm,
831                    (outs GR32:$dst), (ins GR32:$src),
832                    "bswap{l}\t$dst", 
833                    [(set GR32:$dst, (bswap GR32:$src))]>, TB;
834
835
836 // Bit scan instructions.
837 let Defs = [EFLAGS] in {
838 def BSF16rr  : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
839                  "bsf{w}\t{$src, $dst|$dst, $src}",
840                  [(set GR16:$dst, EFLAGS, (X86bsf GR16:$src))]>, TB, OpSize;
841 def BSF16rm  : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
842                  "bsf{w}\t{$src, $dst|$dst, $src}",
843                  [(set GR16:$dst, EFLAGS, (X86bsf (loadi16 addr:$src)))]>, TB,
844                  OpSize;
845 def BSF32rr  : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
846                  "bsf{l}\t{$src, $dst|$dst, $src}",
847                  [(set GR32:$dst, EFLAGS, (X86bsf GR32:$src))]>, TB;
848 def BSF32rm  : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
849                  "bsf{l}\t{$src, $dst|$dst, $src}",
850                  [(set GR32:$dst, EFLAGS, (X86bsf (loadi32 addr:$src)))]>, TB;
851
852 def BSR16rr  : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
853                  "bsr{w}\t{$src, $dst|$dst, $src}",
854                  [(set GR16:$dst, EFLAGS, (X86bsr GR16:$src))]>, TB, OpSize;
855 def BSR16rm  : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
856                  "bsr{w}\t{$src, $dst|$dst, $src}",
857                  [(set GR16:$dst, EFLAGS, (X86bsr (loadi16 addr:$src)))]>, TB,
858                  OpSize;
859 def BSR32rr  : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
860                  "bsr{l}\t{$src, $dst|$dst, $src}",
861                  [(set GR32:$dst, EFLAGS, (X86bsr GR32:$src))]>, TB;
862 def BSR32rm  : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
863                  "bsr{l}\t{$src, $dst|$dst, $src}",
864                  [(set GR32:$dst, EFLAGS, (X86bsr (loadi32 addr:$src)))]>, TB;
865 } // Defs = [EFLAGS]
866
867 let neverHasSideEffects = 1 in
868 def LEA16r   : I<0x8D, MRMSrcMem,
869                  (outs GR16:$dst), (ins i32mem:$src),
870                  "lea{w}\t{$src|$dst}, {$dst|$src}", []>, OpSize;
871 let isReMaterializable = 1 in
872 def LEA32r   : I<0x8D, MRMSrcMem,
873                  (outs GR32:$dst), (ins i32mem:$src),
874                  "lea{l}\t{$src|$dst}, {$dst|$src}",
875                  [(set GR32:$dst, lea32addr:$src)]>, Requires<[In32BitMode]>;
876
877 let Defs = [ECX,EDI,ESI], Uses = [ECX,EDI,ESI], isCodeGenOnly = 1 in {
878 def REP_MOVSB : I<0xA4, RawFrm, (outs), (ins), "{rep;movsb|rep movsb}",
879                   [(X86rep_movs i8)]>, REP;
880 def REP_MOVSW : I<0xA5, RawFrm, (outs), (ins), "{rep;movsw|rep movsw}",
881                   [(X86rep_movs i16)]>, REP, OpSize;
882 def REP_MOVSD : I<0xA5, RawFrm, (outs), (ins), "{rep;movsl|rep movsd}",
883                   [(X86rep_movs i32)]>, REP;
884 }
885
886 // These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
887 let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in {
888 def MOVSB : I<0xA4, RawFrm, (outs), (ins), "{movsb}", []>;
889 def MOVSW : I<0xA5, RawFrm, (outs), (ins), "{movsw}", []>, OpSize;
890 def MOVSD : I<0xA5, RawFrm, (outs), (ins), "{movsl|movsd}", []>;
891 }
892
893 let Defs = [ECX,EDI], Uses = [AL,ECX,EDI], isCodeGenOnly = 1 in
894 def REP_STOSB : I<0xAA, RawFrm, (outs), (ins), "{rep;stosb|rep stosb}",
895                   [(X86rep_stos i8)]>, REP;
896 let Defs = [ECX,EDI], Uses = [AX,ECX,EDI], isCodeGenOnly = 1 in
897 def REP_STOSW : I<0xAB, RawFrm, (outs), (ins), "{rep;stosw|rep stosw}",
898                   [(X86rep_stos i16)]>, REP, OpSize;
899 let Defs = [ECX,EDI], Uses = [EAX,ECX,EDI], isCodeGenOnly = 1 in
900 def REP_STOSD : I<0xAB, RawFrm, (outs), (ins), "{rep;stosl|rep stosd}",
901                   [(X86rep_stos i32)]>, REP;
902
903 // These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
904 let Defs = [EDI], Uses = [AL,EDI,EFLAGS] in
905 def STOSB : I<0xAA, RawFrm, (outs), (ins), "{stosb}", []>;
906 let Defs = [EDI], Uses = [AX,EDI,EFLAGS] in
907 def STOSW : I<0xAB, RawFrm, (outs), (ins), "{stosw}", []>, OpSize;
908 let Defs = [EDI], Uses = [EAX,EDI,EFLAGS] in
909 def STOSD : I<0xAB, RawFrm, (outs), (ins), "{stosl|stosd}", []>;
910
911 def SCAS8 : I<0xAE, RawFrm, (outs), (ins), "scas{b}", []>;
912 def SCAS16 : I<0xAF, RawFrm, (outs), (ins), "scas{w}", []>, OpSize;
913 def SCAS32 : I<0xAF, RawFrm, (outs), (ins), "scas{l}", []>;
914
915 def CMPS8 : I<0xA6, RawFrm, (outs), (ins), "cmps{b}", []>;
916 def CMPS16 : I<0xA7, RawFrm, (outs), (ins), "cmps{w}", []>, OpSize;
917 def CMPS32 : I<0xA7, RawFrm, (outs), (ins), "cmps{l}", []>;
918
919 let Defs = [RAX, RDX] in
920 def RDTSC : I<0x31, RawFrm, (outs), (ins), "rdtsc", [(X86rdtsc)]>,
921             TB;
922
923 let Defs = [RAX, RCX, RDX] in
924 def RDTSCP : I<0x01, MRM_F9, (outs), (ins), "rdtscp", []>, TB;
925
926 let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in {
927 def TRAP    : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB;
928 }
929
930 def SYSCALL  : I<0x05, RawFrm,
931                  (outs), (ins), "syscall", []>, TB;
932 def SYSRET   : I<0x07, RawFrm,
933                  (outs), (ins), "sysret", []>, TB;
934 def SYSENTER : I<0x34, RawFrm,
935                  (outs), (ins), "sysenter", []>, TB;
936 def SYSEXIT  : I<0x35, RawFrm,
937                  (outs), (ins), "sysexit", []>, TB;
938
939 def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
940
941
942 //===----------------------------------------------------------------------===//
943 //  Input/Output Instructions...
944 //
945 let Defs = [AL], Uses = [DX] in
946 def IN8rr  : I<0xEC, RawFrm, (outs), (ins),
947                "in{b}\t{%dx, %al|%AL, %DX}", []>;
948 let Defs = [AX], Uses = [DX] in
949 def IN16rr : I<0xED, RawFrm, (outs), (ins),
950                "in{w}\t{%dx, %ax|%AX, %DX}", []>,  OpSize;
951 let Defs = [EAX], Uses = [DX] in
952 def IN32rr : I<0xED, RawFrm, (outs), (ins),
953                "in{l}\t{%dx, %eax|%EAX, %DX}", []>;
954
955 let Defs = [AL] in
956 def IN8ri  : Ii8<0xE4, RawFrm, (outs), (ins i16i8imm:$port),
957                   "in{b}\t{$port, %al|%AL, $port}", []>;
958 let Defs = [AX] in
959 def IN16ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
960                   "in{w}\t{$port, %ax|%AX, $port}", []>, OpSize;
961 let Defs = [EAX] in
962 def IN32ri : Ii8<0xE5, RawFrm, (outs), (ins i16i8imm:$port),
963                   "in{l}\t{$port, %eax|%EAX, $port}", []>;
964
965 let Uses = [DX, AL] in
966 def OUT8rr  : I<0xEE, RawFrm, (outs), (ins),
967                 "out{b}\t{%al, %dx|%DX, %AL}", []>;
968 let Uses = [DX, AX] in
969 def OUT16rr : I<0xEF, RawFrm, (outs), (ins),
970                 "out{w}\t{%ax, %dx|%DX, %AX}", []>, OpSize;
971 let Uses = [DX, EAX] in
972 def OUT32rr : I<0xEF, RawFrm, (outs), (ins),
973                 "out{l}\t{%eax, %dx|%DX, %EAX}", []>;
974
975 let Uses = [AL] in
976 def OUT8ir  : Ii8<0xE6, RawFrm, (outs), (ins i16i8imm:$port),
977                    "out{b}\t{%al, $port|$port, %AL}", []>;
978 let Uses = [AX] in
979 def OUT16ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
980                    "out{w}\t{%ax, $port|$port, %AX}", []>, OpSize;
981 let Uses = [EAX] in
982 def OUT32ir : Ii8<0xE7, RawFrm, (outs), (ins i16i8imm:$port),
983                    "out{l}\t{%eax, $port|$port, %EAX}", []>;
984
985 def IN8  : I<0x6C, RawFrm, (outs), (ins),
986              "ins{b}", []>;
987 def IN16 : I<0x6D, RawFrm, (outs), (ins),
988              "ins{w}", []>,  OpSize;
989 def IN32 : I<0x6D, RawFrm, (outs), (ins),
990              "ins{l}", []>;
991
992 //===----------------------------------------------------------------------===//
993 //  Move Instructions...
994 //
995 let neverHasSideEffects = 1 in {
996 def MOV8rr  : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src),
997                 "mov{b}\t{$src, $dst|$dst, $src}", []>;
998 def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
999                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1000 def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
1001                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1002 }
1003 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
1004 def MOV8ri  : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src),
1005                    "mov{b}\t{$src, $dst|$dst, $src}",
1006                    [(set GR8:$dst, imm:$src)]>;
1007 def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src),
1008                    "mov{w}\t{$src, $dst|$dst, $src}",
1009                    [(set GR16:$dst, imm:$src)]>, OpSize;
1010 def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src),
1011                    "mov{l}\t{$src, $dst|$dst, $src}",
1012                    [(set GR32:$dst, imm:$src)]>;
1013 }
1014
1015 def MOV8mi  : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src),
1016                    "mov{b}\t{$src, $dst|$dst, $src}",
1017                    [(store (i8 imm:$src), addr:$dst)]>;
1018 def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src),
1019                    "mov{w}\t{$src, $dst|$dst, $src}",
1020                    [(store (i16 imm:$src), addr:$dst)]>, OpSize;
1021 def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src),
1022                    "mov{l}\t{$src, $dst|$dst, $src}",
1023                    [(store (i32 imm:$src), addr:$dst)]>;
1024
1025 /// moffs8, moffs16 and moffs32 versions of moves.  The immediate is a
1026 /// 32-bit offset from the PC.  These are only valid in x86-32 mode.
1027 def MOV8o8a : Ii32 <0xA0, RawFrm, (outs), (ins offset8:$src),
1028                    "mov{b}\t{$src, %al|%al, $src}", []>,
1029                    Requires<[In32BitMode]>;
1030 def MOV16o16a : Ii32 <0xA1, RawFrm, (outs), (ins offset16:$src),
1031                       "mov{w}\t{$src, %ax|%ax, $src}", []>, OpSize,
1032                      Requires<[In32BitMode]>;
1033 def MOV32o32a : Ii32 <0xA1, RawFrm, (outs), (ins offset32:$src),
1034                       "mov{l}\t{$src, %eax|%eax, $src}", []>,
1035                      Requires<[In32BitMode]>;
1036 def MOV8ao8 : Ii32 <0xA2, RawFrm, (outs offset8:$dst), (ins),
1037                    "mov{b}\t{%al, $dst|$dst, %al}", []>,
1038                   Requires<[In32BitMode]>;
1039 def MOV16ao16 : Ii32 <0xA3, RawFrm, (outs offset16:$dst), (ins),
1040                       "mov{w}\t{%ax, $dst|$dst, %ax}", []>, OpSize,
1041                      Requires<[In32BitMode]>;
1042 def MOV32ao32 : Ii32 <0xA3, RawFrm, (outs offset32:$dst), (ins),
1043                       "mov{l}\t{%eax, $dst|$dst, %eax}", []>,
1044                      Requires<[In32BitMode]>;
1045                       
1046 // Moves to and from segment registers
1047 def MOV16rs : I<0x8C, MRMDestReg, (outs GR16:$dst), (ins SEGMENT_REG:$src),
1048                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1049 def MOV32rs : I<0x8C, MRMDestReg, (outs GR32:$dst), (ins SEGMENT_REG:$src),
1050                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1051 def MOV16ms : I<0x8C, MRMDestMem, (outs i16mem:$dst), (ins SEGMENT_REG:$src),
1052                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1053 def MOV32ms : I<0x8C, MRMDestMem, (outs i32mem:$dst), (ins SEGMENT_REG:$src),
1054                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1055 def MOV16sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR16:$src),
1056                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1057 def MOV32sr : I<0x8E, MRMSrcReg, (outs SEGMENT_REG:$dst), (ins GR32:$src),
1058                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1059 def MOV16sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i16mem:$src),
1060                 "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1061 def MOV32sm : I<0x8E, MRMSrcMem, (outs SEGMENT_REG:$dst), (ins i32mem:$src),
1062                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1063
1064 let isCodeGenOnly = 1 in {
1065 def MOV8rr_REV : I<0x8A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src),
1066                    "mov{b}\t{$src, $dst|$dst, $src}", []>;
1067 def MOV16rr_REV : I<0x8B, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
1068                     "mov{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
1069 def MOV32rr_REV : I<0x8B, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
1070                     "mov{l}\t{$src, $dst|$dst, $src}", []>;
1071 }
1072
1073 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1074 def MOV8rm  : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src),
1075                 "mov{b}\t{$src, $dst|$dst, $src}",
1076                 [(set GR8:$dst, (loadi8 addr:$src))]>;
1077 def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
1078                 "mov{w}\t{$src, $dst|$dst, $src}",
1079                 [(set GR16:$dst, (loadi16 addr:$src))]>, OpSize;
1080 def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
1081                 "mov{l}\t{$src, $dst|$dst, $src}",
1082                 [(set GR32:$dst, (loadi32 addr:$src))]>;
1083 }
1084
1085 def MOV8mr  : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src),
1086                 "mov{b}\t{$src, $dst|$dst, $src}",
1087                 [(store GR8:$src, addr:$dst)]>;
1088 def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
1089                 "mov{w}\t{$src, $dst|$dst, $src}",
1090                 [(store GR16:$src, addr:$dst)]>, OpSize;
1091 def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
1092                 "mov{l}\t{$src, $dst|$dst, $src}",
1093                 [(store GR32:$src, addr:$dst)]>;
1094
1095 /// Versions of MOV32rr, MOV32rm, and MOV32mr for i32mem_TC and GR32_TC.
1096 let neverHasSideEffects = 1 in
1097 def MOV32rr_TC : I<0x89, MRMDestReg, (outs GR32_TC:$dst), (ins GR32_TC:$src),
1098                 "mov{l}\t{$src, $dst|$dst, $src}", []>;
1099
1100 let mayLoad = 1,
1101     canFoldAsLoad = 1, isReMaterializable = 1 in
1102 def MOV32rm_TC : I<0x8B, MRMSrcMem, (outs GR32_TC:$dst), (ins i32mem_TC:$src),
1103                 "mov{l}\t{$src, $dst|$dst, $src}",
1104                 []>;
1105
1106 let mayStore = 1 in
1107 def MOV32mr_TC : I<0x89, MRMDestMem, (outs), (ins i32mem_TC:$dst, GR32_TC:$src),
1108                 "mov{l}\t{$src, $dst|$dst, $src}",
1109                 []>;
1110
1111 // Versions of MOV8rr, MOV8mr, and MOV8rm that use i8mem_NOREX and GR8_NOREX so
1112 // that they can be used for copying and storing h registers, which can't be
1113 // encoded when a REX prefix is present.
1114 let neverHasSideEffects = 1 in
1115 def MOV8rr_NOREX : I<0x88, MRMDestReg,
1116                      (outs GR8_NOREX:$dst), (ins GR8_NOREX:$src),
1117                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
1118 let mayStore = 1 in
1119 def MOV8mr_NOREX : I<0x88, MRMDestMem,
1120                      (outs), (ins i8mem_NOREX:$dst, GR8_NOREX:$src),
1121                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
1122 let mayLoad = 1,
1123     canFoldAsLoad = 1, isReMaterializable = 1 in
1124 def MOV8rm_NOREX : I<0x8A, MRMSrcMem,
1125                      (outs GR8_NOREX:$dst), (ins i8mem_NOREX:$src),
1126                      "mov{b}\t{$src, $dst|$dst, $src}  # NOREX", []>;
1127
1128 // Moves to and from debug registers
1129 def MOV32rd : I<0x21, MRMDestReg, (outs GR32:$dst), (ins DEBUG_REG:$src),
1130                 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1131 def MOV32dr : I<0x23, MRMSrcReg, (outs DEBUG_REG:$dst), (ins GR32:$src),
1132                 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1133                 
1134 // Moves to and from control registers
1135 def MOV32rc : I<0x20, MRMDestReg, (outs GR32:$dst), (ins CONTROL_REG:$src),
1136                 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1137 def MOV32cr : I<0x22, MRMSrcReg, (outs CONTROL_REG:$dst), (ins GR32:$src),
1138                 "mov{l}\t{$src, $dst|$dst, $src}", []>, TB;
1139
1140 //===----------------------------------------------------------------------===//
1141 //  Fixed-Register Multiplication and Division Instructions...
1142 //
1143
1144 // Extra precision multiplication
1145
1146 // AL is really implied by AX, by the registers in Defs must match the
1147 // SDNode results (i8, i32).
1148 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
1149 def MUL8r  : I<0xF6, MRM4r, (outs),  (ins GR8:$src), "mul{b}\t$src",
1150                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
1151                // This probably ought to be moved to a def : Pat<> if the
1152                // syntax can be accepted.
1153                [(set AL, (mul AL, GR8:$src)),
1154                 (implicit EFLAGS)]>;     // AL,AH = AL*GR8
1155
1156 let Defs = [AX,DX,EFLAGS], Uses = [AX], neverHasSideEffects = 1 in
1157 def MUL16r : I<0xF7, MRM4r, (outs),  (ins GR16:$src),
1158                "mul{w}\t$src", 
1159                []>, OpSize;    // AX,DX = AX*GR16
1160
1161 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX], neverHasSideEffects = 1 in
1162 def MUL32r : I<0xF7, MRM4r, (outs),  (ins GR32:$src),
1163                "mul{l}\t$src",
1164                []>; // EAX,EDX = EAX*GR32
1165
1166 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
1167 def MUL8m  : I<0xF6, MRM4m, (outs), (ins i8mem :$src),
1168                "mul{b}\t$src",
1169                // FIXME: Used for 8-bit mul, ignore result upper 8 bits.
1170                // This probably ought to be moved to a def : Pat<> if the
1171                // syntax can be accepted.
1172                [(set AL, (mul AL, (loadi8 addr:$src))),
1173                 (implicit EFLAGS)]>;   // AL,AH = AL*[mem8]
1174
1175 let mayLoad = 1, neverHasSideEffects = 1 in {
1176 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
1177 def MUL16m : I<0xF7, MRM4m, (outs), (ins i16mem:$src),
1178                "mul{w}\t$src",
1179                []>, OpSize; // AX,DX = AX*[mem16]
1180
1181 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
1182 def MUL32m : I<0xF7, MRM4m, (outs), (ins i32mem:$src),
1183               "mul{l}\t$src",
1184               []>;          // EAX,EDX = EAX*[mem32]
1185 }
1186
1187 let neverHasSideEffects = 1 in {
1188 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
1189 def IMUL8r  : I<0xF6, MRM5r, (outs),  (ins GR8:$src), "imul{b}\t$src", []>;
1190               // AL,AH = AL*GR8
1191 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
1192 def IMUL16r : I<0xF7, MRM5r, (outs),  (ins GR16:$src), "imul{w}\t$src", []>,
1193               OpSize;    // AX,DX = AX*GR16
1194 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
1195 def IMUL32r : I<0xF7, MRM5r, (outs),  (ins GR32:$src), "imul{l}\t$src", []>;
1196               // EAX,EDX = EAX*GR32
1197 let mayLoad = 1 in {
1198 let Defs = [AL,EFLAGS,AX], Uses = [AL] in
1199 def IMUL8m  : I<0xF6, MRM5m, (outs), (ins i8mem :$src),
1200                 "imul{b}\t$src", []>;    // AL,AH = AL*[mem8]
1201 let Defs = [AX,DX,EFLAGS], Uses = [AX] in
1202 def IMUL16m : I<0xF7, MRM5m, (outs), (ins i16mem:$src),
1203                 "imul{w}\t$src", []>, OpSize; // AX,DX = AX*[mem16]
1204 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX] in
1205 def IMUL32m : I<0xF7, MRM5m, (outs), (ins i32mem:$src),
1206                 "imul{l}\t$src", []>;  // EAX,EDX = EAX*[mem32]
1207 }
1208 } // neverHasSideEffects
1209
1210 // unsigned division/remainder
1211 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
1212 def DIV8r  : I<0xF6, MRM6r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
1213                "div{b}\t$src", []>;
1214 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
1215 def DIV16r : I<0xF7, MRM6r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
1216                "div{w}\t$src", []>, OpSize;
1217 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
1218 def DIV32r : I<0xF7, MRM6r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
1219                "div{l}\t$src", []>;
1220 let mayLoad = 1 in {
1221 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
1222 def DIV8m  : I<0xF6, MRM6m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
1223                "div{b}\t$src", []>;
1224 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
1225 def DIV16m : I<0xF7, MRM6m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
1226                "div{w}\t$src", []>, OpSize;
1227 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
1228                                                     // EDX:EAX/[mem32] = EAX,EDX
1229 def DIV32m : I<0xF7, MRM6m, (outs), (ins i32mem:$src),
1230                "div{l}\t$src", []>;
1231 }
1232
1233 // Signed division/remainder.
1234 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
1235 def IDIV8r : I<0xF6, MRM7r, (outs),  (ins GR8:$src),    // AX/r8 = AL,AH
1236                "idiv{b}\t$src", []>;
1237 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
1238 def IDIV16r: I<0xF7, MRM7r, (outs),  (ins GR16:$src),   // DX:AX/r16 = AX,DX
1239                "idiv{w}\t$src", []>, OpSize;
1240 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
1241 def IDIV32r: I<0xF7, MRM7r, (outs),  (ins GR32:$src),   // EDX:EAX/r32 = EAX,EDX
1242                "idiv{l}\t$src", []>;
1243 let mayLoad = 1, mayLoad = 1 in {
1244 let Defs = [AL,EFLAGS,AX], Uses = [AX] in
1245 def IDIV8m : I<0xF6, MRM7m, (outs), (ins i8mem:$src),   // AX/[mem8] = AL,AH
1246                "idiv{b}\t$src", []>;
1247 let Defs = [AX,DX,EFLAGS], Uses = [AX,DX] in
1248 def IDIV16m: I<0xF7, MRM7m, (outs), (ins i16mem:$src),  // DX:AX/[mem16] = AX,DX
1249                "idiv{w}\t$src", []>, OpSize;
1250 let Defs = [EAX,EDX,EFLAGS], Uses = [EAX,EDX] in
1251 def IDIV32m: I<0xF7, MRM7m, (outs), (ins i32mem:$src), 
1252                                                     // EDX:EAX/[mem32] = EAX,EDX
1253                "idiv{l}\t$src", []>;
1254 }
1255
1256 //===----------------------------------------------------------------------===//
1257 //  Two address Instructions.
1258 //
1259 let Constraints = "$src1 = $dst" in {
1260
1261 // Conditional moves
1262 let Uses = [EFLAGS] in {
1263
1264 let Predicates = [HasCMov] in {
1265 let isCommutable = 1 in {
1266 def CMOVB16rr : I<0x42, MRMSrcReg,       // if <u, GR16 = GR16
1267                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1268                   "cmovb{w}\t{$src2, $dst|$dst, $src2}",
1269                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1270                                    X86_COND_B, EFLAGS))]>,
1271                   TB, OpSize;
1272 def CMOVB32rr : I<0x42, MRMSrcReg,       // if <u, GR32 = GR32
1273                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1274                   "cmovb{l}\t{$src2, $dst|$dst, $src2}",
1275                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1276                                    X86_COND_B, EFLAGS))]>,
1277                    TB;
1278 def CMOVAE16rr: I<0x43, MRMSrcReg,       // if >=u, GR16 = GR16
1279                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1280                   "cmovae{w}\t{$src2, $dst|$dst, $src2}",
1281                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1282                                    X86_COND_AE, EFLAGS))]>,
1283                    TB, OpSize;
1284 def CMOVAE32rr: I<0x43, MRMSrcReg,       // if >=u, GR32 = GR32
1285                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1286                   "cmovae{l}\t{$src2, $dst|$dst, $src2}",
1287                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1288                                    X86_COND_AE, EFLAGS))]>,
1289                    TB;
1290 def CMOVE16rr : I<0x44, MRMSrcReg,       // if ==, GR16 = GR16
1291                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1292                   "cmove{w}\t{$src2, $dst|$dst, $src2}",
1293                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1294                                    X86_COND_E, EFLAGS))]>,
1295                    TB, OpSize;
1296 def CMOVE32rr : I<0x44, MRMSrcReg,       // if ==, GR32 = GR32
1297                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1298                   "cmove{l}\t{$src2, $dst|$dst, $src2}",
1299                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1300                                    X86_COND_E, EFLAGS))]>,
1301                    TB;
1302 def CMOVNE16rr: I<0x45, MRMSrcReg,       // if !=, GR16 = GR16
1303                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1304                   "cmovne{w}\t{$src2, $dst|$dst, $src2}",
1305                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1306                                    X86_COND_NE, EFLAGS))]>,
1307                    TB, OpSize;
1308 def CMOVNE32rr: I<0x45, MRMSrcReg,       // if !=, GR32 = GR32
1309                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1310                   "cmovne{l}\t{$src2, $dst|$dst, $src2}",
1311                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1312                                    X86_COND_NE, EFLAGS))]>,
1313                    TB;
1314 def CMOVBE16rr: I<0x46, MRMSrcReg,       // if <=u, GR16 = GR16
1315                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1316                   "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
1317                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1318                                    X86_COND_BE, EFLAGS))]>,
1319                    TB, OpSize;
1320 def CMOVBE32rr: I<0x46, MRMSrcReg,       // if <=u, GR32 = GR32
1321                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1322                   "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
1323                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1324                                    X86_COND_BE, EFLAGS))]>,
1325                    TB;
1326 def CMOVA16rr : I<0x47, MRMSrcReg,       // if >u, GR16 = GR16
1327                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1328                   "cmova{w}\t{$src2, $dst|$dst, $src2}",
1329                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1330                                    X86_COND_A, EFLAGS))]>,
1331                    TB, OpSize;
1332 def CMOVA32rr : I<0x47, MRMSrcReg,       // if >u, GR32 = GR32
1333                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1334                   "cmova{l}\t{$src2, $dst|$dst, $src2}",
1335                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1336                                    X86_COND_A, EFLAGS))]>,
1337                    TB;
1338 def CMOVL16rr : I<0x4C, MRMSrcReg,       // if <s, GR16 = GR16
1339                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1340                   "cmovl{w}\t{$src2, $dst|$dst, $src2}",
1341                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1342                                    X86_COND_L, EFLAGS))]>,
1343                    TB, OpSize;
1344 def CMOVL32rr : I<0x4C, MRMSrcReg,       // if <s, GR32 = GR32
1345                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1346                   "cmovl{l}\t{$src2, $dst|$dst, $src2}",
1347                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1348                                    X86_COND_L, EFLAGS))]>,
1349                    TB;
1350 def CMOVGE16rr: I<0x4D, MRMSrcReg,       // if >=s, GR16 = GR16
1351                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1352                   "cmovge{w}\t{$src2, $dst|$dst, $src2}",
1353                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1354                                    X86_COND_GE, EFLAGS))]>,
1355                    TB, OpSize;
1356 def CMOVGE32rr: I<0x4D, MRMSrcReg,       // if >=s, GR32 = GR32
1357                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1358                   "cmovge{l}\t{$src2, $dst|$dst, $src2}",
1359                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1360                                    X86_COND_GE, EFLAGS))]>,
1361                    TB;
1362 def CMOVLE16rr: I<0x4E, MRMSrcReg,       // if <=s, GR16 = GR16
1363                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1364                   "cmovle{w}\t{$src2, $dst|$dst, $src2}",
1365                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1366                                    X86_COND_LE, EFLAGS))]>,
1367                    TB, OpSize;
1368 def CMOVLE32rr: I<0x4E, MRMSrcReg,       // if <=s, GR32 = GR32
1369                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1370                   "cmovle{l}\t{$src2, $dst|$dst, $src2}",
1371                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1372                                    X86_COND_LE, EFLAGS))]>,
1373                    TB;
1374 def CMOVG16rr : I<0x4F, MRMSrcReg,       // if >s, GR16 = GR16
1375                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1376                   "cmovg{w}\t{$src2, $dst|$dst, $src2}",
1377                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1378                                    X86_COND_G, EFLAGS))]>,
1379                    TB, OpSize;
1380 def CMOVG32rr : I<0x4F, MRMSrcReg,       // if >s, GR32 = GR32
1381                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1382                   "cmovg{l}\t{$src2, $dst|$dst, $src2}",
1383                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1384                                    X86_COND_G, EFLAGS))]>,
1385                    TB;
1386 def CMOVS16rr : I<0x48, MRMSrcReg,       // if signed, GR16 = GR16
1387                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1388                   "cmovs{w}\t{$src2, $dst|$dst, $src2}",
1389                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1390                                    X86_COND_S, EFLAGS))]>,
1391                   TB, OpSize;
1392 def CMOVS32rr : I<0x48, MRMSrcReg,       // if signed, GR32 = GR32
1393                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1394                   "cmovs{l}\t{$src2, $dst|$dst, $src2}",
1395                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1396                                    X86_COND_S, EFLAGS))]>,
1397                   TB;
1398 def CMOVNS16rr: I<0x49, MRMSrcReg,       // if !signed, GR16 = GR16
1399                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1400                   "cmovns{w}\t{$src2, $dst|$dst, $src2}",
1401                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1402                                    X86_COND_NS, EFLAGS))]>,
1403                   TB, OpSize;
1404 def CMOVNS32rr: I<0x49, MRMSrcReg,       // if !signed, GR32 = GR32
1405                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1406                   "cmovns{l}\t{$src2, $dst|$dst, $src2}",
1407                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1408                                    X86_COND_NS, EFLAGS))]>,
1409                   TB;
1410 def CMOVP16rr : I<0x4A, MRMSrcReg,       // if parity, GR16 = GR16
1411                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1412                   "cmovp{w}\t{$src2, $dst|$dst, $src2}",
1413                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1414                                    X86_COND_P, EFLAGS))]>,
1415                   TB, OpSize;
1416 def CMOVP32rr : I<0x4A, MRMSrcReg,       // if parity, GR32 = GR32
1417                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1418                   "cmovp{l}\t{$src2, $dst|$dst, $src2}",
1419                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1420                                    X86_COND_P, EFLAGS))]>,
1421                   TB;
1422 def CMOVNP16rr : I<0x4B, MRMSrcReg,       // if !parity, GR16 = GR16
1423                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1424                   "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
1425                    [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1426                                     X86_COND_NP, EFLAGS))]>,
1427                   TB, OpSize;
1428 def CMOVNP32rr : I<0x4B, MRMSrcReg,       // if !parity, GR32 = GR32
1429                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1430                   "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
1431                    [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1432                                     X86_COND_NP, EFLAGS))]>,
1433                   TB;
1434 def CMOVO16rr : I<0x40, MRMSrcReg,       // if overflow, GR16 = GR16
1435                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1436                   "cmovo{w}\t{$src2, $dst|$dst, $src2}",
1437                   [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1438                                    X86_COND_O, EFLAGS))]>,
1439                   TB, OpSize;
1440 def CMOVO32rr : I<0x40, MRMSrcReg,       // if overflow, GR32 = GR32
1441                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1442                   "cmovo{l}\t{$src2, $dst|$dst, $src2}",
1443                   [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1444                                    X86_COND_O, EFLAGS))]>,
1445                   TB;
1446 def CMOVNO16rr : I<0x41, MRMSrcReg,       // if !overflow, GR16 = GR16
1447                   (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1448                   "cmovno{w}\t{$src2, $dst|$dst, $src2}",
1449                    [(set GR16:$dst, (X86cmov GR16:$src1, GR16:$src2,
1450                                     X86_COND_NO, EFLAGS))]>,
1451                   TB, OpSize;
1452 def CMOVNO32rr : I<0x41, MRMSrcReg,       // if !overflow, GR32 = GR32
1453                   (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1454                   "cmovno{l}\t{$src2, $dst|$dst, $src2}",
1455                    [(set GR32:$dst, (X86cmov GR32:$src1, GR32:$src2,
1456                                     X86_COND_NO, EFLAGS))]>,
1457                   TB;
1458 } // isCommutable = 1
1459
1460 def CMOVB16rm : I<0x42, MRMSrcMem,       // if <u, GR16 = [mem16]
1461                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1462                   "cmovb{w}\t{$src2, $dst|$dst, $src2}",
1463                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1464                                    X86_COND_B, EFLAGS))]>,
1465                   TB, OpSize;
1466 def CMOVB32rm : I<0x42, MRMSrcMem,       // if <u, GR32 = [mem32]
1467                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1468                   "cmovb{l}\t{$src2, $dst|$dst, $src2}",
1469                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1470                                    X86_COND_B, EFLAGS))]>,
1471                    TB;
1472 def CMOVAE16rm: I<0x43, MRMSrcMem,       // if >=u, GR16 = [mem16]
1473                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1474                   "cmovae{w}\t{$src2, $dst|$dst, $src2}",
1475                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1476                                    X86_COND_AE, EFLAGS))]>,
1477                    TB, OpSize;
1478 def CMOVAE32rm: I<0x43, MRMSrcMem,       // if >=u, GR32 = [mem32]
1479                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1480                   "cmovae{l}\t{$src2, $dst|$dst, $src2}",
1481                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1482                                    X86_COND_AE, EFLAGS))]>,
1483                    TB;
1484 def CMOVE16rm : I<0x44, MRMSrcMem,       // if ==, GR16 = [mem16]
1485                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1486                   "cmove{w}\t{$src2, $dst|$dst, $src2}",
1487                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1488                                    X86_COND_E, EFLAGS))]>,
1489                    TB, OpSize;
1490 def CMOVE32rm : I<0x44, MRMSrcMem,       // if ==, GR32 = [mem32]
1491                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1492                   "cmove{l}\t{$src2, $dst|$dst, $src2}",
1493                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1494                                    X86_COND_E, EFLAGS))]>,
1495                    TB;
1496 def CMOVNE16rm: I<0x45, MRMSrcMem,       // if !=, GR16 = [mem16]
1497                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1498                   "cmovne{w}\t{$src2, $dst|$dst, $src2}",
1499                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1500                                    X86_COND_NE, EFLAGS))]>,
1501                    TB, OpSize;
1502 def CMOVNE32rm: I<0x45, MRMSrcMem,       // if !=, GR32 = [mem32]
1503                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1504                   "cmovne{l}\t{$src2, $dst|$dst, $src2}",
1505                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1506                                    X86_COND_NE, EFLAGS))]>,
1507                    TB;
1508 def CMOVBE16rm: I<0x46, MRMSrcMem,       // if <=u, GR16 = [mem16]
1509                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1510                   "cmovbe{w}\t{$src2, $dst|$dst, $src2}",
1511                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1512                                    X86_COND_BE, EFLAGS))]>,
1513                    TB, OpSize;
1514 def CMOVBE32rm: I<0x46, MRMSrcMem,       // if <=u, GR32 = [mem32]
1515                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1516                   "cmovbe{l}\t{$src2, $dst|$dst, $src2}",
1517                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1518                                    X86_COND_BE, EFLAGS))]>,
1519                    TB;
1520 def CMOVA16rm : I<0x47, MRMSrcMem,       // if >u, GR16 = [mem16]
1521                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1522                   "cmova{w}\t{$src2, $dst|$dst, $src2}",
1523                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1524                                    X86_COND_A, EFLAGS))]>,
1525                    TB, OpSize;
1526 def CMOVA32rm : I<0x47, MRMSrcMem,       // if >u, GR32 = [mem32]
1527                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1528                   "cmova{l}\t{$src2, $dst|$dst, $src2}",
1529                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1530                                    X86_COND_A, EFLAGS))]>,
1531                    TB;
1532 def CMOVL16rm : I<0x4C, MRMSrcMem,       // if <s, GR16 = [mem16]
1533                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1534                   "cmovl{w}\t{$src2, $dst|$dst, $src2}",
1535                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1536                                    X86_COND_L, EFLAGS))]>,
1537                    TB, OpSize;
1538 def CMOVL32rm : I<0x4C, MRMSrcMem,       // if <s, GR32 = [mem32]
1539                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1540                   "cmovl{l}\t{$src2, $dst|$dst, $src2}",
1541                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1542                                    X86_COND_L, EFLAGS))]>,
1543                    TB;
1544 def CMOVGE16rm: I<0x4D, MRMSrcMem,       // if >=s, GR16 = [mem16]
1545                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1546                   "cmovge{w}\t{$src2, $dst|$dst, $src2}",
1547                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1548                                    X86_COND_GE, EFLAGS))]>,
1549                    TB, OpSize;
1550 def CMOVGE32rm: I<0x4D, MRMSrcMem,       // if >=s, GR32 = [mem32]
1551                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1552                   "cmovge{l}\t{$src2, $dst|$dst, $src2}",
1553                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1554                                    X86_COND_GE, EFLAGS))]>,
1555                    TB;
1556 def CMOVLE16rm: I<0x4E, MRMSrcMem,       // if <=s, GR16 = [mem16]
1557                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1558                   "cmovle{w}\t{$src2, $dst|$dst, $src2}",
1559                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1560                                    X86_COND_LE, EFLAGS))]>,
1561                    TB, OpSize;
1562 def CMOVLE32rm: I<0x4E, MRMSrcMem,       // if <=s, GR32 = [mem32]
1563                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1564                   "cmovle{l}\t{$src2, $dst|$dst, $src2}",
1565                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1566                                    X86_COND_LE, EFLAGS))]>,
1567                    TB;
1568 def CMOVG16rm : I<0x4F, MRMSrcMem,       // if >s, GR16 = [mem16]
1569                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1570                   "cmovg{w}\t{$src2, $dst|$dst, $src2}",
1571                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1572                                    X86_COND_G, EFLAGS))]>,
1573                    TB, OpSize;
1574 def CMOVG32rm : I<0x4F, MRMSrcMem,       // if >s, GR32 = [mem32]
1575                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1576                   "cmovg{l}\t{$src2, $dst|$dst, $src2}",
1577                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1578                                    X86_COND_G, EFLAGS))]>,
1579                    TB;
1580 def CMOVS16rm : I<0x48, MRMSrcMem,       // if signed, GR16 = [mem16]
1581                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1582                   "cmovs{w}\t{$src2, $dst|$dst, $src2}",
1583                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1584                                    X86_COND_S, EFLAGS))]>,
1585                   TB, OpSize;
1586 def CMOVS32rm : I<0x48, MRMSrcMem,       // if signed, GR32 = [mem32]
1587                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1588                   "cmovs{l}\t{$src2, $dst|$dst, $src2}",
1589                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1590                                    X86_COND_S, EFLAGS))]>,
1591                   TB;
1592 def CMOVNS16rm: I<0x49, MRMSrcMem,       // if !signed, GR16 = [mem16]
1593                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1594                   "cmovns{w}\t{$src2, $dst|$dst, $src2}",
1595                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1596                                    X86_COND_NS, EFLAGS))]>,
1597                   TB, OpSize;
1598 def CMOVNS32rm: I<0x49, MRMSrcMem,       // if !signed, GR32 = [mem32]
1599                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1600                   "cmovns{l}\t{$src2, $dst|$dst, $src2}",
1601                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1602                                    X86_COND_NS, EFLAGS))]>,
1603                   TB;
1604 def CMOVP16rm : I<0x4A, MRMSrcMem,       // if parity, GR16 = [mem16]
1605                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1606                   "cmovp{w}\t{$src2, $dst|$dst, $src2}",
1607                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1608                                    X86_COND_P, EFLAGS))]>,
1609                   TB, OpSize;
1610 def CMOVP32rm : I<0x4A, MRMSrcMem,       // if parity, GR32 = [mem32]
1611                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1612                   "cmovp{l}\t{$src2, $dst|$dst, $src2}",
1613                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1614                                    X86_COND_P, EFLAGS))]>,
1615                   TB;
1616 def CMOVNP16rm : I<0x4B, MRMSrcMem,       // if !parity, GR16 = [mem16]
1617                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1618                   "cmovnp{w}\t{$src2, $dst|$dst, $src2}",
1619                    [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1620                                     X86_COND_NP, EFLAGS))]>,
1621                   TB, OpSize;
1622 def CMOVNP32rm : I<0x4B, MRMSrcMem,       // if !parity, GR32 = [mem32]
1623                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1624                   "cmovnp{l}\t{$src2, $dst|$dst, $src2}",
1625                    [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1626                                     X86_COND_NP, EFLAGS))]>,
1627                   TB;
1628 def CMOVO16rm : I<0x40, MRMSrcMem,       // if overflow, GR16 = [mem16]
1629                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1630                   "cmovo{w}\t{$src2, $dst|$dst, $src2}",
1631                   [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1632                                    X86_COND_O, EFLAGS))]>,
1633                   TB, OpSize;
1634 def CMOVO32rm : I<0x40, MRMSrcMem,       // if overflow, GR32 = [mem32]
1635                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1636                   "cmovo{l}\t{$src2, $dst|$dst, $src2}",
1637                   [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1638                                    X86_COND_O, EFLAGS))]>,
1639                   TB;
1640 def CMOVNO16rm : I<0x41, MRMSrcMem,       // if !overflow, GR16 = [mem16]
1641                   (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1642                   "cmovno{w}\t{$src2, $dst|$dst, $src2}",
1643                    [(set GR16:$dst, (X86cmov GR16:$src1, (loadi16 addr:$src2),
1644                                     X86_COND_NO, EFLAGS))]>,
1645                   TB, OpSize;
1646 def CMOVNO32rm : I<0x41, MRMSrcMem,       // if !overflow, GR32 = [mem32]
1647                   (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1648                   "cmovno{l}\t{$src2, $dst|$dst, $src2}",
1649                    [(set GR32:$dst, (X86cmov GR32:$src1, (loadi32 addr:$src2),
1650                                     X86_COND_NO, EFLAGS))]>,
1651                   TB;
1652 } // Predicates = [HasCMov]
1653
1654 // X86 doesn't have 8-bit conditional moves. Use a customInserter to
1655 // emit control flow. An alternative to this is to mark i8 SELECT as Promote,
1656 // however that requires promoting the operands, and can induce additional
1657 // i8 register pressure. Note that CMOV_GR8 is conservatively considered to
1658 // clobber EFLAGS, because if one of the operands is zero, the expansion
1659 // could involve an xor.
1660 let usesCustomInserter = 1, Constraints = "", Defs = [EFLAGS] in {
1661 def CMOV_GR8 : I<0, Pseudo,
1662                  (outs GR8:$dst), (ins GR8:$src1, GR8:$src2, i8imm:$cond),
1663                  "#CMOV_GR8 PSEUDO!",
1664                  [(set GR8:$dst, (X86cmov GR8:$src1, GR8:$src2,
1665                                           imm:$cond, EFLAGS))]>;
1666
1667 let Predicates = [NoCMov] in {
1668 def CMOV_GR32 : I<0, Pseudo,
1669                     (outs GR32:$dst), (ins GR32:$src1, GR32:$src2, i8imm:$cond),
1670                     "#CMOV_GR32* PSEUDO!",
1671                     [(set GR32:$dst,
1672                       (X86cmov GR32:$src1, GR32:$src2, imm:$cond, EFLAGS))]>;
1673 def CMOV_GR16 : I<0, Pseudo,
1674                     (outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$cond),
1675                     "#CMOV_GR16* PSEUDO!",
1676                     [(set GR16:$dst,
1677                       (X86cmov GR16:$src1, GR16:$src2, imm:$cond, EFLAGS))]>;
1678 def CMOV_RFP32 : I<0, Pseudo,
1679                     (outs RFP32:$dst),
1680                     (ins RFP32:$src1, RFP32:$src2, i8imm:$cond),
1681                     "#CMOV_RFP32 PSEUDO!",
1682                     [(set RFP32:$dst,
1683                       (X86cmov RFP32:$src1, RFP32:$src2, imm:$cond,
1684                                                   EFLAGS))]>;
1685 def CMOV_RFP64 : I<0, Pseudo,
1686                     (outs RFP64:$dst),
1687                     (ins RFP64:$src1, RFP64:$src2, i8imm:$cond),
1688                     "#CMOV_RFP64 PSEUDO!",
1689                     [(set RFP64:$dst,
1690                       (X86cmov RFP64:$src1, RFP64:$src2, imm:$cond,
1691                                                   EFLAGS))]>;
1692 def CMOV_RFP80 : I<0, Pseudo,
1693                     (outs RFP80:$dst),
1694                     (ins RFP80:$src1, RFP80:$src2, i8imm:$cond),
1695                     "#CMOV_RFP80 PSEUDO!",
1696                     [(set RFP80:$dst,
1697                       (X86cmov RFP80:$src1, RFP80:$src2, imm:$cond,
1698                                                   EFLAGS))]>;
1699 } // Predicates = [NoCMov]
1700 } // UsesCustomInserter = 1, Constraints = "", Defs = [EFLAGS] 
1701 } // Uses = [EFLAGS]
1702
1703
1704 // unary instructions
1705 let CodeSize = 2 in {
1706 let Defs = [EFLAGS] in {
1707 def NEG8r  : I<0xF6, MRM3r, (outs GR8 :$dst), (ins GR8 :$src1),
1708                "neg{b}\t$dst",
1709                [(set GR8:$dst, (ineg GR8:$src1)),
1710                 (implicit EFLAGS)]>;
1711 def NEG16r : I<0xF7, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
1712                "neg{w}\t$dst",
1713                [(set GR16:$dst, (ineg GR16:$src1)),
1714                 (implicit EFLAGS)]>, OpSize;
1715 def NEG32r : I<0xF7, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
1716                "neg{l}\t$dst",
1717                [(set GR32:$dst, (ineg GR32:$src1)),
1718                 (implicit EFLAGS)]>;
1719                 
1720 let Constraints = "" in {
1721   def NEG8m  : I<0xF6, MRM3m, (outs), (ins i8mem :$dst),
1722                  "neg{b}\t$dst",
1723                  [(store (ineg (loadi8 addr:$dst)), addr:$dst),
1724                   (implicit EFLAGS)]>;
1725   def NEG16m : I<0xF7, MRM3m, (outs), (ins i16mem:$dst),
1726                  "neg{w}\t$dst",
1727                  [(store (ineg (loadi16 addr:$dst)), addr:$dst),
1728                   (implicit EFLAGS)]>, OpSize;
1729   def NEG32m : I<0xF7, MRM3m, (outs), (ins i32mem:$dst),
1730                  "neg{l}\t$dst",
1731                  [(store (ineg (loadi32 addr:$dst)), addr:$dst),
1732                   (implicit EFLAGS)]>;
1733 } // Constraints = ""
1734 } // Defs = [EFLAGS]
1735
1736 // Match xor -1 to not. Favors these over a move imm + xor to save code size.
1737 let AddedComplexity = 15 in {
1738 def NOT8r  : I<0xF6, MRM2r, (outs GR8 :$dst), (ins GR8 :$src1),
1739                "not{b}\t$dst",
1740                [(set GR8:$dst, (not GR8:$src1))]>;
1741 def NOT16r : I<0xF7, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
1742                "not{w}\t$dst",
1743                [(set GR16:$dst, (not GR16:$src1))]>, OpSize;
1744 def NOT32r : I<0xF7, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
1745                "not{l}\t$dst",
1746                [(set GR32:$dst, (not GR32:$src1))]>;
1747 }
1748 let Constraints = "" in {
1749   def NOT8m  : I<0xF6, MRM2m, (outs), (ins i8mem :$dst),
1750                  "not{b}\t$dst",
1751                  [(store (not (loadi8 addr:$dst)), addr:$dst)]>;
1752   def NOT16m : I<0xF7, MRM2m, (outs), (ins i16mem:$dst),
1753                  "not{w}\t$dst",
1754                  [(store (not (loadi16 addr:$dst)), addr:$dst)]>, OpSize;
1755   def NOT32m : I<0xF7, MRM2m, (outs), (ins i32mem:$dst),
1756                  "not{l}\t$dst",
1757                  [(store (not (loadi32 addr:$dst)), addr:$dst)]>;
1758 } // Constraints = ""
1759 } // CodeSize
1760
1761 // TODO: inc/dec is slow for P4, but fast for Pentium-M.
1762 let Defs = [EFLAGS] in {
1763 let CodeSize = 2 in
1764 def INC8r  : I<0xFE, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
1765                "inc{b}\t$dst",
1766                [(set GR8:$dst, EFLAGS, (X86inc_flag GR8:$src1))]>;
1767
1768 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {  // Can xform into LEA.
1769 def INC16r : I<0x40, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
1770                "inc{w}\t$dst",
1771                [(set GR16:$dst, EFLAGS, (X86inc_flag GR16:$src1))]>,
1772              OpSize, Requires<[In32BitMode]>;
1773 def INC32r : I<0x40, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
1774                "inc{l}\t$dst",
1775                [(set GR32:$dst, EFLAGS, (X86inc_flag GR32:$src1))]>,
1776              Requires<[In32BitMode]>;
1777 }
1778 let Constraints = "", CodeSize = 2 in {
1779   def INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst), "inc{b}\t$dst",
1780                [(store (add (loadi8 addr:$dst), 1), addr:$dst),
1781                 (implicit EFLAGS)]>;
1782   def INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst), "inc{w}\t$dst",
1783                [(store (add (loadi16 addr:$dst), 1), addr:$dst),
1784                 (implicit EFLAGS)]>,
1785                OpSize, Requires<[In32BitMode]>;
1786   def INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst), "inc{l}\t$dst",
1787                [(store (add (loadi32 addr:$dst), 1), addr:$dst),
1788                 (implicit EFLAGS)]>,
1789                Requires<[In32BitMode]>;
1790 } // Constraints = "", CodeSize = 2
1791
1792 let CodeSize = 2 in
1793 def DEC8r  : I<0xFE, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
1794                "dec{b}\t$dst",
1795                [(set GR8:$dst, EFLAGS, (X86dec_flag GR8:$src1))]>;
1796 let isConvertibleToThreeAddress = 1, CodeSize = 1 in {   // Can xform into LEA.
1797 def DEC16r : I<0x48, AddRegFrm, (outs GR16:$dst), (ins GR16:$src1), 
1798                "dec{w}\t$dst",
1799                [(set GR16:$dst, EFLAGS, (X86dec_flag GR16:$src1))]>,
1800              OpSize, Requires<[In32BitMode]>;
1801 def DEC32r : I<0x48, AddRegFrm, (outs GR32:$dst), (ins GR32:$src1), 
1802                "dec{l}\t$dst",
1803                [(set GR32:$dst, EFLAGS, (X86dec_flag GR32:$src1))]>,
1804              Requires<[In32BitMode]>;
1805 } // CodeSize = 2
1806
1807 let Constraints = "", CodeSize = 2 in {
1808   def DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst), "dec{b}\t$dst",
1809                [(store (add (loadi8 addr:$dst), -1), addr:$dst),
1810                 (implicit EFLAGS)]>;
1811   def DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst), "dec{w}\t$dst",
1812                [(store (add (loadi16 addr:$dst), -1), addr:$dst),
1813                 (implicit EFLAGS)]>,
1814                OpSize, Requires<[In32BitMode]>;
1815   def DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst), "dec{l}\t$dst",
1816                [(store (add (loadi32 addr:$dst), -1), addr:$dst),
1817                 (implicit EFLAGS)]>,
1818                Requires<[In32BitMode]>;
1819 } // Constraints = "", CodeSize = 2
1820 } // Defs = [EFLAGS]
1821
1822 // Logical operators...
1823 let Defs = [EFLAGS] in {
1824 let isCommutable = 1 in {   // X = AND Y, Z   --> X = AND Z, Y
1825 def AND8rr  : I<0x20, MRMDestReg,
1826                (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
1827                "and{b}\t{$src2, $dst|$dst, $src2}",
1828                [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1, GR8:$src2))]>;
1829 def AND16rr : I<0x21, MRMDestReg,
1830                 (outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
1831                 "and{w}\t{$src2, $dst|$dst, $src2}",
1832                 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1833                                                       GR16:$src2))]>, OpSize;
1834 def AND32rr : I<0x21, MRMDestReg, 
1835                 (outs GR32:$dst), (ins GR32:$src1, GR32:$src2),
1836                 "and{l}\t{$src2, $dst|$dst, $src2}",
1837                 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1838                                                       GR32:$src2))]>;
1839 }
1840
1841 // AND instructions with the destination register in REG and the source register
1842 //   in R/M.  Included for the disassembler.
1843 let isCodeGenOnly = 1 in {
1844 def AND8rr_REV : I<0x22, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1845                   "and{b}\t{$src2, $dst|$dst, $src2}", []>;
1846 def AND16rr_REV : I<0x23, MRMSrcReg, (outs GR16:$dst), 
1847                     (ins GR16:$src1, GR16:$src2),
1848                    "and{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1849 def AND32rr_REV : I<0x23, MRMSrcReg, (outs GR32:$dst), 
1850                     (ins GR32:$src1, GR32:$src2),
1851                    "and{l}\t{$src2, $dst|$dst, $src2}", []>;
1852 }
1853
1854 def AND8rm   : I<0x22, MRMSrcMem, 
1855                  (outs GR8 :$dst), (ins GR8 :$src1, i8mem :$src2),
1856                  "and{b}\t{$src2, $dst|$dst, $src2}",
1857                 [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1858                                                      (loadi8 addr:$src2)))]>;
1859 def AND16rm  : I<0x23, MRMSrcMem, 
1860                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2),
1861                  "and{w}\t{$src2, $dst|$dst, $src2}",
1862                 [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1863                                                       (loadi16 addr:$src2)))]>,
1864                OpSize;
1865 def AND32rm  : I<0x23, MRMSrcMem,
1866                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2),
1867                  "and{l}\t{$src2, $dst|$dst, $src2}",
1868                 [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1869                                                       (loadi32 addr:$src2)))]>;
1870
1871 def AND8ri   : Ii8<0x80, MRM4r, 
1872                    (outs GR8 :$dst), (ins GR8 :$src1, i8imm :$src2),
1873                    "and{b}\t{$src2, $dst|$dst, $src2}",
1874                    [(set GR8:$dst, EFLAGS, (X86and_flag GR8:$src1,
1875                                                         imm:$src2))]>;
1876 def AND16ri  : Ii16<0x81, MRM4r, 
1877                     (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
1878                     "and{w}\t{$src2, $dst|$dst, $src2}",
1879                     [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1880                                                           imm:$src2))]>, OpSize;
1881 def AND32ri  : Ii32<0x81, MRM4r, 
1882                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
1883                     "and{l}\t{$src2, $dst|$dst, $src2}",
1884                     [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1885                                                           imm:$src2))]>;
1886 def AND16ri8 : Ii8<0x83, MRM4r, 
1887                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
1888                    "and{w}\t{$src2, $dst|$dst, $src2}",
1889                    [(set GR16:$dst, EFLAGS, (X86and_flag GR16:$src1,
1890                                                          i16immSExt8:$src2))]>,
1891                    OpSize;
1892 def AND32ri8 : Ii8<0x83, MRM4r, 
1893                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
1894                    "and{l}\t{$src2, $dst|$dst, $src2}",
1895                    [(set GR32:$dst, EFLAGS, (X86and_flag GR32:$src1,
1896                                                          i32immSExt8:$src2))]>;
1897
1898 let Constraints = "" in {
1899   def AND8mr   : I<0x20, MRMDestMem,
1900                    (outs), (ins i8mem :$dst, GR8 :$src),
1901                    "and{b}\t{$src, $dst|$dst, $src}",
1902                    [(store (and (load addr:$dst), GR8:$src), addr:$dst),
1903                     (implicit EFLAGS)]>;
1904   def AND16mr  : I<0x21, MRMDestMem,
1905                    (outs), (ins i16mem:$dst, GR16:$src),
1906                    "and{w}\t{$src, $dst|$dst, $src}",
1907                    [(store (and (load addr:$dst), GR16:$src), addr:$dst),
1908                     (implicit EFLAGS)]>,
1909                    OpSize;
1910   def AND32mr  : I<0x21, MRMDestMem,
1911                    (outs), (ins i32mem:$dst, GR32:$src),
1912                    "and{l}\t{$src, $dst|$dst, $src}",
1913                    [(store (and (load addr:$dst), GR32:$src), addr:$dst),
1914                     (implicit EFLAGS)]>;
1915   def AND8mi   : Ii8<0x80, MRM4m,
1916                      (outs), (ins i8mem :$dst, i8imm :$src),
1917                      "and{b}\t{$src, $dst|$dst, $src}",
1918                       [(store (and (loadi8 addr:$dst), imm:$src), addr:$dst),
1919                        (implicit EFLAGS)]>;
1920   def AND16mi  : Ii16<0x81, MRM4m,
1921                       (outs), (ins i16mem:$dst, i16imm:$src),
1922                       "and{w}\t{$src, $dst|$dst, $src}",
1923                       [(store (and (loadi16 addr:$dst), imm:$src), addr:$dst),
1924                        (implicit EFLAGS)]>,
1925                       OpSize;
1926   def AND32mi  : Ii32<0x81, MRM4m,
1927                       (outs), (ins i32mem:$dst, i32imm:$src),
1928                       "and{l}\t{$src, $dst|$dst, $src}",
1929                       [(store (and (loadi32 addr:$dst), imm:$src), addr:$dst),
1930                        (implicit EFLAGS)]>;
1931   def AND16mi8 : Ii8<0x83, MRM4m,
1932                      (outs), (ins i16mem:$dst, i16i8imm :$src),
1933                      "and{w}\t{$src, $dst|$dst, $src}",
1934                 [(store (and (load addr:$dst), i16immSExt8:$src), addr:$dst),
1935                  (implicit EFLAGS)]>,
1936                      OpSize;
1937   def AND32mi8 : Ii8<0x83, MRM4m,
1938                      (outs), (ins i32mem:$dst, i32i8imm :$src),
1939                      "and{l}\t{$src, $dst|$dst, $src}",
1940                 [(store (and (load addr:$dst), i32immSExt8:$src), addr:$dst),
1941                  (implicit EFLAGS)]>;
1942
1943   def AND8i8 : Ii8<0x24, RawFrm, (outs), (ins i8imm:$src),
1944                    "and{b}\t{$src, %al|%al, $src}", []>;
1945   def AND16i16 : Ii16<0x25, RawFrm, (outs), (ins i16imm:$src),
1946                       "and{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
1947   def AND32i32 : Ii32<0x25, RawFrm, (outs), (ins i32imm:$src),
1948                       "and{l}\t{$src, %eax|%eax, $src}", []>;
1949
1950 } // Constraints = ""
1951
1952
1953 let isCommutable = 1 in {   // X = OR Y, Z   --> X = OR Z, Y
1954 def OR8rr    : I<0x08, MRMDestReg, (outs GR8 :$dst), 
1955                  (ins GR8 :$src1, GR8 :$src2),
1956                  "or{b}\t{$src2, $dst|$dst, $src2}",
1957                  [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1, GR8:$src2))]>;
1958 def OR16rr   : I<0x09, MRMDestReg, (outs GR16:$dst), 
1959                  (ins GR16:$src1, GR16:$src2),
1960                  "or{w}\t{$src2, $dst|$dst, $src2}",
1961                  [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,GR16:$src2))]>,
1962                OpSize;
1963 def OR32rr   : I<0x09, MRMDestReg, (outs GR32:$dst), 
1964                  (ins GR32:$src1, GR32:$src2),
1965                  "or{l}\t{$src2, $dst|$dst, $src2}",
1966                  [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,GR32:$src2))]>;
1967 }
1968
1969 // OR instructions with the destination register in REG and the source register
1970 //   in R/M.  Included for the disassembler.
1971 let isCodeGenOnly = 1 in {
1972 def OR8rr_REV : I<0x0A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
1973                   "or{b}\t{$src2, $dst|$dst, $src2}", []>;
1974 def OR16rr_REV : I<0x0B, MRMSrcReg, (outs GR16:$dst),
1975                    (ins GR16:$src1, GR16:$src2),
1976                    "or{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
1977 def OR32rr_REV : I<0x0B, MRMSrcReg, (outs GR32:$dst), 
1978                    (ins GR32:$src1, GR32:$src2),
1979                    "or{l}\t{$src2, $dst|$dst, $src2}", []>;
1980 }
1981                   
1982 def OR8rm    : I<0x0A, MRMSrcMem, (outs GR8 :$dst), 
1983                  (ins GR8 :$src1, i8mem :$src2),
1984                  "or{b}\t{$src2, $dst|$dst, $src2}",
1985                 [(set GR8:$dst, EFLAGS, (X86or_flag GR8:$src1,
1986                                                     (load addr:$src2)))]>;
1987 def OR16rm   : I<0x0B, MRMSrcMem, (outs GR16:$dst), 
1988                  (ins GR16:$src1, i16mem:$src2),
1989                  "or{w}\t{$src2, $dst|$dst, $src2}",
1990                 [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
1991                                                      (load addr:$src2)))]>,
1992                OpSize;
1993 def OR32rm   : I<0x0B, MRMSrcMem, (outs GR32:$dst), 
1994                  (ins GR32:$src1, i32mem:$src2),
1995                  "or{l}\t{$src2, $dst|$dst, $src2}",
1996                 [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
1997                                                      (load addr:$src2)))]>;
1998
1999 def OR8ri    : Ii8 <0x80, MRM1r, (outs GR8 :$dst), 
2000                     (ins GR8 :$src1, i8imm:$src2),
2001                     "or{b}\t{$src2, $dst|$dst, $src2}",
2002                     [(set GR8:$dst,EFLAGS, (X86or_flag GR8:$src1, imm:$src2))]>;
2003 def OR16ri   : Ii16<0x81, MRM1r, (outs GR16:$dst), 
2004                     (ins GR16:$src1, i16imm:$src2),
2005                     "or{w}\t{$src2, $dst|$dst, $src2}", 
2006                     [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
2007                                                         imm:$src2))]>, OpSize;
2008 def OR32ri   : Ii32<0x81, MRM1r, (outs GR32:$dst), 
2009                     (ins GR32:$src1, i32imm:$src2),
2010                     "or{l}\t{$src2, $dst|$dst, $src2}",
2011                     [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
2012                                                          imm:$src2))]>;
2013
2014 def OR16ri8  : Ii8<0x83, MRM1r, (outs GR16:$dst), 
2015                    (ins GR16:$src1, i16i8imm:$src2),
2016                    "or{w}\t{$src2, $dst|$dst, $src2}",
2017                    [(set GR16:$dst, EFLAGS, (X86or_flag GR16:$src1,
2018                                                 i16immSExt8:$src2))]>, OpSize;
2019 def OR32ri8  : Ii8<0x83, MRM1r, (outs GR32:$dst), 
2020                    (ins GR32:$src1, i32i8imm:$src2),
2021                    "or{l}\t{$src2, $dst|$dst, $src2}",
2022                    [(set GR32:$dst, EFLAGS, (X86or_flag GR32:$src1,
2023                                                         i32immSExt8:$src2))]>;
2024 let Constraints = "" in {
2025   def OR8mr  : I<0x08, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
2026                  "or{b}\t{$src, $dst|$dst, $src}",
2027                  [(store (or (load addr:$dst), GR8:$src), addr:$dst),
2028                   (implicit EFLAGS)]>;
2029   def OR16mr : I<0x09, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
2030                  "or{w}\t{$src, $dst|$dst, $src}",
2031                  [(store (or (load addr:$dst), GR16:$src), addr:$dst),
2032                   (implicit EFLAGS)]>, OpSize;
2033   def OR32mr : I<0x09, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
2034                  "or{l}\t{$src, $dst|$dst, $src}",
2035                  [(store (or (load addr:$dst), GR32:$src), addr:$dst),
2036                   (implicit EFLAGS)]>;
2037   def OR8mi    : Ii8<0x80, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
2038                  "or{b}\t{$src, $dst|$dst, $src}",
2039                  [(store (or (loadi8 addr:$dst), imm:$src), addr:$dst),
2040                   (implicit EFLAGS)]>;
2041   def OR16mi   : Ii16<0x81, MRM1m, (outs), (ins i16mem:$dst, i16imm:$src),
2042                  "or{w}\t{$src, $dst|$dst, $src}",
2043                  [(store (or (loadi16 addr:$dst), imm:$src), addr:$dst),
2044                   (implicit EFLAGS)]>,
2045                  OpSize;
2046   def OR32mi   : Ii32<0x81, MRM1m, (outs), (ins i32mem:$dst, i32imm:$src),
2047                  "or{l}\t{$src, $dst|$dst, $src}",
2048                  [(store (or (loadi32 addr:$dst), imm:$src), addr:$dst),
2049                   (implicit EFLAGS)]>;
2050   def OR16mi8  : Ii8<0x83, MRM1m, (outs), (ins i16mem:$dst, i16i8imm:$src),
2051                  "or{w}\t{$src, $dst|$dst, $src}",
2052                  [(store (or (load addr:$dst), i16immSExt8:$src), addr:$dst),
2053                   (implicit EFLAGS)]>,
2054                      OpSize;
2055   def OR32mi8  : Ii8<0x83, MRM1m, (outs), (ins i32mem:$dst, i32i8imm:$src),
2056                  "or{l}\t{$src, $dst|$dst, $src}",
2057                  [(store (or (load addr:$dst), i32immSExt8:$src), addr:$dst),
2058                   (implicit EFLAGS)]>;
2059                   
2060   def OR8i8 : Ii8 <0x0C, RawFrm, (outs), (ins i8imm:$src),
2061                    "or{b}\t{$src, %al|%al, $src}", []>;
2062   def OR16i16 : Ii16 <0x0D, RawFrm, (outs), (ins i16imm:$src),
2063                       "or{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2064   def OR32i32 : Ii32 <0x0D, RawFrm, (outs), (ins i32imm:$src),
2065                       "or{l}\t{$src, %eax|%eax, $src}", []>;
2066 } // Constraints = ""
2067
2068
2069 let isCommutable = 1 in { // X = XOR Y, Z --> X = XOR Z, Y
2070   def XOR8rr   : I<0x30, MRMDestReg,
2071                    (outs GR8 :$dst), (ins GR8 :$src1, GR8 :$src2),
2072                    "xor{b}\t{$src2, $dst|$dst, $src2}",
2073                    [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
2074                                                         GR8:$src2))]>;
2075   def XOR16rr  : I<0x31, MRMDestReg, 
2076                    (outs GR16:$dst), (ins GR16:$src1, GR16:$src2), 
2077                    "xor{w}\t{$src2, $dst|$dst, $src2}",
2078                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2079                                                          GR16:$src2))]>, OpSize;
2080   def XOR32rr  : I<0x31, MRMDestReg, 
2081                    (outs GR32:$dst), (ins GR32:$src1, GR32:$src2), 
2082                    "xor{l}\t{$src2, $dst|$dst, $src2}",
2083                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2084                                                          GR32:$src2))]>;
2085 } // isCommutable = 1
2086
2087 // XOR instructions with the destination register in REG and the source register
2088 //   in R/M.  Included for the disassembler.
2089 let isCodeGenOnly = 1 in {
2090 def XOR8rr_REV : I<0x32, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2091                   "xor{b}\t{$src2, $dst|$dst, $src2}", []>;
2092 def XOR16rr_REV : I<0x33, MRMSrcReg, (outs GR16:$dst), 
2093                     (ins GR16:$src1, GR16:$src2),
2094                    "xor{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2095 def XOR32rr_REV : I<0x33, MRMSrcReg, (outs GR32:$dst), 
2096                     (ins GR32:$src1, GR32:$src2),
2097                    "xor{l}\t{$src2, $dst|$dst, $src2}", []>;
2098 }
2099
2100 def XOR8rm   : I<0x32, MRMSrcMem, 
2101                  (outs GR8 :$dst), (ins GR8:$src1, i8mem :$src2), 
2102                  "xor{b}\t{$src2, $dst|$dst, $src2}",
2103                  [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1,
2104                                                       (load addr:$src2)))]>;
2105 def XOR16rm  : I<0x33, MRMSrcMem, 
2106                  (outs GR16:$dst), (ins GR16:$src1, i16mem:$src2), 
2107                  "xor{w}\t{$src2, $dst|$dst, $src2}",
2108                  [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2109                                                        (load addr:$src2)))]>,
2110                  OpSize;
2111 def XOR32rm  : I<0x33, MRMSrcMem, 
2112                  (outs GR32:$dst), (ins GR32:$src1, i32mem:$src2), 
2113                  "xor{l}\t{$src2, $dst|$dst, $src2}",
2114                  [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2115                                                        (load addr:$src2)))]>;
2116
2117 def XOR8ri  : Ii8<0x80, MRM6r, 
2118                   (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2), 
2119                   "xor{b}\t{$src2, $dst|$dst, $src2}",
2120                   [(set GR8:$dst, EFLAGS, (X86xor_flag GR8:$src1, imm:$src2))]>;
2121 def XOR16ri : Ii16<0x81, MRM6r, 
2122                    (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2), 
2123                    "xor{w}\t{$src2, $dst|$dst, $src2}",
2124                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2125                                                          imm:$src2))]>, OpSize;
2126 def XOR32ri  : Ii32<0x81, MRM6r, 
2127                     (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2), 
2128                     "xor{l}\t{$src2, $dst|$dst, $src2}",
2129                     [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2130                                                           imm:$src2))]>;
2131 def XOR16ri8 : Ii8<0x83, MRM6r, 
2132                    (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
2133                    "xor{w}\t{$src2, $dst|$dst, $src2}",
2134                    [(set GR16:$dst, EFLAGS, (X86xor_flag GR16:$src1,
2135                                                          i16immSExt8:$src2))]>,
2136                    OpSize;
2137 def XOR32ri8 : Ii8<0x83, MRM6r, 
2138                    (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
2139                    "xor{l}\t{$src2, $dst|$dst, $src2}",
2140                    [(set GR32:$dst, EFLAGS, (X86xor_flag GR32:$src1,
2141                                                          i32immSExt8:$src2))]>;
2142
2143 let Constraints = "" in {
2144   def XOR8mr   : I<0x30, MRMDestMem,
2145                    (outs), (ins i8mem :$dst, GR8 :$src),
2146                    "xor{b}\t{$src, $dst|$dst, $src}",
2147                    [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
2148                     (implicit EFLAGS)]>;
2149   def XOR16mr  : I<0x31, MRMDestMem,
2150                    (outs), (ins i16mem:$dst, GR16:$src),
2151                    "xor{w}\t{$src, $dst|$dst, $src}",
2152                    [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
2153                     (implicit EFLAGS)]>,
2154                    OpSize;
2155   def XOR32mr  : I<0x31, MRMDestMem,
2156                    (outs), (ins i32mem:$dst, GR32:$src),
2157                    "xor{l}\t{$src, $dst|$dst, $src}",
2158                    [(store (xor (load addr:$dst), GR32:$src), addr:$dst),
2159                     (implicit EFLAGS)]>;
2160   def XOR8mi   : Ii8<0x80, MRM6m,
2161                      (outs), (ins i8mem :$dst, i8imm :$src),
2162                      "xor{b}\t{$src, $dst|$dst, $src}",
2163                     [(store (xor (loadi8 addr:$dst), imm:$src), addr:$dst),
2164                      (implicit EFLAGS)]>;
2165   def XOR16mi  : Ii16<0x81, MRM6m,
2166                       (outs), (ins i16mem:$dst, i16imm:$src),
2167                       "xor{w}\t{$src, $dst|$dst, $src}",
2168                    [(store (xor (loadi16 addr:$dst), imm:$src), addr:$dst),
2169                     (implicit EFLAGS)]>,
2170                       OpSize;
2171   def XOR32mi  : Ii32<0x81, MRM6m,
2172                       (outs), (ins i32mem:$dst, i32imm:$src),
2173                       "xor{l}\t{$src, $dst|$dst, $src}",
2174                    [(store (xor (loadi32 addr:$dst), imm:$src), addr:$dst),
2175                     (implicit EFLAGS)]>;
2176   def XOR16mi8 : Ii8<0x83, MRM6m,
2177                      (outs), (ins i16mem:$dst, i16i8imm :$src),
2178                      "xor{w}\t{$src, $dst|$dst, $src}",
2179                  [(store (xor (load addr:$dst), i16immSExt8:$src), addr:$dst),
2180                   (implicit EFLAGS)]>,
2181                      OpSize;
2182   def XOR32mi8 : Ii8<0x83, MRM6m,
2183                      (outs), (ins i32mem:$dst, i32i8imm :$src),
2184                      "xor{l}\t{$src, $dst|$dst, $src}",
2185                  [(store (xor (load addr:$dst), i32immSExt8:$src), addr:$dst),
2186                   (implicit EFLAGS)]>;
2187                   
2188   def XOR8i8   : Ii8 <0x34, RawFrm, (outs), (ins i8imm:$src),
2189                       "xor{b}\t{$src, %al|%al, $src}", []>;
2190   def XOR16i16 : Ii16<0x35, RawFrm, (outs), (ins i16imm:$src),
2191                       "xor{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2192   def XOR32i32 : Ii32<0x35, RawFrm, (outs), (ins i32imm:$src),
2193                       "xor{l}\t{$src, %eax|%eax, $src}", []>;
2194 } // Constraints = ""
2195 } // Defs = [EFLAGS]
2196
2197 // Shift instructions
2198 let Defs = [EFLAGS] in {
2199 let Uses = [CL] in {
2200 def SHL8rCL  : I<0xD2, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1),
2201                  "shl{b}\t{%cl, $dst|$dst, CL}",
2202                  [(set GR8:$dst, (shl GR8:$src1, CL))]>;
2203 def SHL16rCL : I<0xD3, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
2204                  "shl{w}\t{%cl, $dst|$dst, CL}",
2205                  [(set GR16:$dst, (shl GR16:$src1, CL))]>, OpSize;
2206 def SHL32rCL : I<0xD3, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
2207                  "shl{l}\t{%cl, $dst|$dst, CL}",
2208                  [(set GR32:$dst, (shl GR32:$src1, CL))]>;
2209 } // Uses = [CL]
2210
2211 def SHL8ri   : Ii8<0xC0, MRM4r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2212                    "shl{b}\t{$src2, $dst|$dst, $src2}",
2213                    [(set GR8:$dst, (shl GR8:$src1, (i8 imm:$src2)))]>;
2214                    
2215 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2216 def SHL16ri  : Ii8<0xC1, MRM4r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2217                    "shl{w}\t{$src2, $dst|$dst, $src2}",
2218                    [(set GR16:$dst, (shl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
2219 def SHL32ri  : Ii8<0xC1, MRM4r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2220                    "shl{l}\t{$src2, $dst|$dst, $src2}",
2221                    [(set GR32:$dst, (shl GR32:$src1, (i8 imm:$src2)))]>;
2222
2223 // NOTE: We don't include patterns for shifts of a register by one, because
2224 // 'add reg,reg' is cheaper.
2225
2226 def SHL8r1   : I<0xD0, MRM4r, (outs GR8:$dst), (ins GR8:$src1),
2227                  "shl{b}\t$dst", []>;
2228 def SHL16r1  : I<0xD1, MRM4r, (outs GR16:$dst), (ins GR16:$src1),
2229                  "shl{w}\t$dst", []>, OpSize;
2230 def SHL32r1  : I<0xD1, MRM4r, (outs GR32:$dst), (ins GR32:$src1),
2231                  "shl{l}\t$dst", []>;
2232
2233 } // isConvertibleToThreeAddress = 1
2234
2235 let Constraints = "" in {
2236   let Uses = [CL] in {
2237   def SHL8mCL  : I<0xD2, MRM4m, (outs), (ins i8mem :$dst),
2238                    "shl{b}\t{%cl, $dst|$dst, CL}",
2239                    [(store (shl (loadi8 addr:$dst), CL), addr:$dst)]>;
2240   def SHL16mCL : I<0xD3, MRM4m, (outs), (ins i16mem:$dst),
2241                    "shl{w}\t{%cl, $dst|$dst, CL}",
2242                    [(store (shl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2243   def SHL32mCL : I<0xD3, MRM4m, (outs), (ins i32mem:$dst),
2244                    "shl{l}\t{%cl, $dst|$dst, CL}",
2245                    [(store (shl (loadi32 addr:$dst), CL), addr:$dst)]>;
2246   }
2247   def SHL8mi   : Ii8<0xC0, MRM4m, (outs), (ins i8mem :$dst, i8imm:$src),
2248                      "shl{b}\t{$src, $dst|$dst, $src}",
2249                   [(store (shl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2250   def SHL16mi  : Ii8<0xC1, MRM4m, (outs), (ins i16mem:$dst, i8imm:$src),
2251                      "shl{w}\t{$src, $dst|$dst, $src}",
2252                  [(store (shl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2253                      OpSize;
2254   def SHL32mi  : Ii8<0xC1, MRM4m, (outs), (ins i32mem:$dst, i8imm:$src),
2255                      "shl{l}\t{$src, $dst|$dst, $src}",
2256                  [(store (shl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2257
2258   // Shift by 1
2259   def SHL8m1   : I<0xD0, MRM4m, (outs), (ins i8mem :$dst),
2260                    "shl{b}\t$dst",
2261                   [(store (shl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2262   def SHL16m1  : I<0xD1, MRM4m, (outs), (ins i16mem:$dst),
2263                    "shl{w}\t$dst",
2264                  [(store (shl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2265                      OpSize;
2266   def SHL32m1  : I<0xD1, MRM4m, (outs), (ins i32mem:$dst),
2267                    "shl{l}\t$dst",
2268                  [(store (shl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2269 } // Constraints = ""
2270
2271 let Uses = [CL] in {
2272 def SHR8rCL  : I<0xD2, MRM5r, (outs GR8 :$dst), (ins GR8 :$src1),
2273                  "shr{b}\t{%cl, $dst|$dst, CL}",
2274                  [(set GR8:$dst, (srl GR8:$src1, CL))]>;
2275 def SHR16rCL : I<0xD3, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
2276                  "shr{w}\t{%cl, $dst|$dst, CL}",
2277                  [(set GR16:$dst, (srl GR16:$src1, CL))]>, OpSize;
2278 def SHR32rCL : I<0xD3, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
2279                  "shr{l}\t{%cl, $dst|$dst, CL}",
2280                  [(set GR32:$dst, (srl GR32:$src1, CL))]>;
2281 }
2282
2283 def SHR8ri   : Ii8<0xC0, MRM5r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2284                    "shr{b}\t{$src2, $dst|$dst, $src2}",
2285                    [(set GR8:$dst, (srl GR8:$src1, (i8 imm:$src2)))]>;
2286 def SHR16ri  : Ii8<0xC1, MRM5r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2287                    "shr{w}\t{$src2, $dst|$dst, $src2}",
2288                    [(set GR16:$dst, (srl GR16:$src1, (i8 imm:$src2)))]>, OpSize;
2289 def SHR32ri  : Ii8<0xC1, MRM5r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2290                    "shr{l}\t{$src2, $dst|$dst, $src2}",
2291                    [(set GR32:$dst, (srl GR32:$src1, (i8 imm:$src2)))]>;
2292
2293 // Shift by 1
2294 def SHR8r1   : I<0xD0, MRM5r, (outs GR8:$dst), (ins GR8:$src1),
2295                  "shr{b}\t$dst",
2296                  [(set GR8:$dst, (srl GR8:$src1, (i8 1)))]>;
2297 def SHR16r1  : I<0xD1, MRM5r, (outs GR16:$dst), (ins GR16:$src1),
2298                  "shr{w}\t$dst",
2299                  [(set GR16:$dst, (srl GR16:$src1, (i8 1)))]>, OpSize;
2300 def SHR32r1  : I<0xD1, MRM5r, (outs GR32:$dst), (ins GR32:$src1),
2301                  "shr{l}\t$dst",
2302                  [(set GR32:$dst, (srl GR32:$src1, (i8 1)))]>;
2303
2304 let Constraints = "" in {
2305   let Uses = [CL] in {
2306   def SHR8mCL  : I<0xD2, MRM5m, (outs), (ins i8mem :$dst),
2307                    "shr{b}\t{%cl, $dst|$dst, CL}",
2308                    [(store (srl (loadi8 addr:$dst), CL), addr:$dst)]>;
2309   def SHR16mCL : I<0xD3, MRM5m, (outs), (ins i16mem:$dst),
2310                    "shr{w}\t{%cl, $dst|$dst, CL}",
2311                    [(store (srl (loadi16 addr:$dst), CL), addr:$dst)]>,
2312                    OpSize;
2313   def SHR32mCL : I<0xD3, MRM5m, (outs), (ins i32mem:$dst),
2314                    "shr{l}\t{%cl, $dst|$dst, CL}",
2315                    [(store (srl (loadi32 addr:$dst), CL), addr:$dst)]>;
2316   }
2317   def SHR8mi   : Ii8<0xC0, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src),
2318                      "shr{b}\t{$src, $dst|$dst, $src}",
2319                   [(store (srl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2320   def SHR16mi  : Ii8<0xC1, MRM5m, (outs), (ins i16mem:$dst, i8imm:$src),
2321                      "shr{w}\t{$src, $dst|$dst, $src}",
2322                  [(store (srl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2323                      OpSize;
2324   def SHR32mi  : Ii8<0xC1, MRM5m, (outs), (ins i32mem:$dst, i8imm:$src),
2325                      "shr{l}\t{$src, $dst|$dst, $src}",
2326                  [(store (srl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2327
2328   // Shift by 1
2329   def SHR8m1   : I<0xD0, MRM5m, (outs), (ins i8mem :$dst),
2330                    "shr{b}\t$dst",
2331                   [(store (srl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2332   def SHR16m1  : I<0xD1, MRM5m, (outs), (ins i16mem:$dst),
2333                    "shr{w}\t$dst",
2334                  [(store (srl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,OpSize;
2335   def SHR32m1  : I<0xD1, MRM5m, (outs), (ins i32mem:$dst),
2336                    "shr{l}\t$dst",
2337                  [(store (srl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2338 } // Constraints = ""
2339
2340 let Uses = [CL] in {
2341 def SAR8rCL  : I<0xD2, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
2342                  "sar{b}\t{%cl, $dst|$dst, CL}",
2343                  [(set GR8:$dst, (sra GR8:$src1, CL))]>;
2344 def SAR16rCL : I<0xD3, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
2345                  "sar{w}\t{%cl, $dst|$dst, CL}",
2346                  [(set GR16:$dst, (sra GR16:$src1, CL))]>, OpSize;
2347 def SAR32rCL : I<0xD3, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
2348                  "sar{l}\t{%cl, $dst|$dst, CL}",
2349                  [(set GR32:$dst, (sra GR32:$src1, CL))]>;
2350 }
2351
2352 def SAR8ri   : Ii8<0xC0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2353                    "sar{b}\t{$src2, $dst|$dst, $src2}",
2354                    [(set GR8:$dst, (sra GR8:$src1, (i8 imm:$src2)))]>;
2355 def SAR16ri  : Ii8<0xC1, MRM7r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2356                    "sar{w}\t{$src2, $dst|$dst, $src2}",
2357                    [(set GR16:$dst, (sra GR16:$src1, (i8 imm:$src2)))]>,
2358                    OpSize;
2359 def SAR32ri  : Ii8<0xC1, MRM7r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2360                    "sar{l}\t{$src2, $dst|$dst, $src2}",
2361                    [(set GR32:$dst, (sra GR32:$src1, (i8 imm:$src2)))]>;
2362
2363 // Shift by 1
2364 def SAR8r1   : I<0xD0, MRM7r, (outs GR8 :$dst), (ins GR8 :$src1),
2365                  "sar{b}\t$dst",
2366                  [(set GR8:$dst, (sra GR8:$src1, (i8 1)))]>;
2367 def SAR16r1  : I<0xD1, MRM7r, (outs GR16:$dst), (ins GR16:$src1),
2368                  "sar{w}\t$dst",
2369                  [(set GR16:$dst, (sra GR16:$src1, (i8 1)))]>, OpSize;
2370 def SAR32r1  : I<0xD1, MRM7r, (outs GR32:$dst), (ins GR32:$src1),
2371                  "sar{l}\t$dst",
2372                  [(set GR32:$dst, (sra GR32:$src1, (i8 1)))]>;
2373
2374 let Constraints = "" in {
2375   let Uses = [CL] in {
2376   def SAR8mCL  : I<0xD2, MRM7m, (outs), (ins i8mem :$dst),
2377                    "sar{b}\t{%cl, $dst|$dst, CL}",
2378                    [(store (sra (loadi8 addr:$dst), CL), addr:$dst)]>;
2379   def SAR16mCL : I<0xD3, MRM7m, (outs), (ins i16mem:$dst),
2380                    "sar{w}\t{%cl, $dst|$dst, CL}",
2381                    [(store (sra (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2382   def SAR32mCL : I<0xD3, MRM7m, (outs), (ins i32mem:$dst), 
2383                    "sar{l}\t{%cl, $dst|$dst, CL}",
2384                    [(store (sra (loadi32 addr:$dst), CL), addr:$dst)]>;
2385   }
2386   def SAR8mi   : Ii8<0xC0, MRM7m, (outs), (ins i8mem :$dst, i8imm:$src),
2387                      "sar{b}\t{$src, $dst|$dst, $src}",
2388                   [(store (sra (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2389   def SAR16mi  : Ii8<0xC1, MRM7m, (outs), (ins i16mem:$dst, i8imm:$src),
2390                      "sar{w}\t{$src, $dst|$dst, $src}",
2391                  [(store (sra (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2392                      OpSize;
2393   def SAR32mi  : Ii8<0xC1, MRM7m, (outs), (ins i32mem:$dst, i8imm:$src),
2394                      "sar{l}\t{$src, $dst|$dst, $src}",
2395                  [(store (sra (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2396
2397   // Shift by 1
2398   def SAR8m1   : I<0xD0, MRM7m, (outs), (ins i8mem :$dst),
2399                    "sar{b}\t$dst",
2400                   [(store (sra (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2401   def SAR16m1  : I<0xD1, MRM7m, (outs), (ins i16mem:$dst),
2402                    "sar{w}\t$dst",
2403                  [(store (sra (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2404                      OpSize;
2405   def SAR32m1  : I<0xD1, MRM7m, (outs), (ins i32mem:$dst),
2406                    "sar{l}\t$dst",
2407                  [(store (sra (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2408 } // Constraints = ""
2409
2410 // Rotate instructions
2411
2412 def RCL8r1 : I<0xD0, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
2413                "rcl{b}\t{1, $dst|$dst, 1}", []>;
2414 let Uses = [CL] in {
2415 def RCL8rCL : I<0xD2, MRM2r, (outs GR8:$dst), (ins GR8:$src1),
2416                 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
2417 }
2418 def RCL8ri : Ii8<0xC0, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
2419                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2420   
2421 def RCL16r1 : I<0xD1, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
2422                 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2423 let Uses = [CL] in {
2424 def RCL16rCL : I<0xD3, MRM2r, (outs GR16:$dst), (ins GR16:$src1),
2425                  "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2426 }
2427 def RCL16ri : Ii8<0xC1, MRM2r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
2428                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2429
2430 def RCL32r1 : I<0xD1, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
2431                 "rcl{l}\t{1, $dst|$dst, 1}", []>;
2432 let Uses = [CL] in {
2433 def RCL32rCL : I<0xD3, MRM2r, (outs GR32:$dst), (ins GR32:$src1),
2434                  "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
2435 }
2436 def RCL32ri : Ii8<0xC1, MRM2r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
2437                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2438                   
2439 def RCR8r1 : I<0xD0, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
2440                "rcr{b}\t{1, $dst|$dst, 1}", []>;
2441 let Uses = [CL] in {
2442 def RCR8rCL : I<0xD2, MRM3r, (outs GR8:$dst), (ins GR8:$src1),
2443                 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
2444 }
2445 def RCR8ri : Ii8<0xC0, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$cnt),
2446                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2447   
2448 def RCR16r1 : I<0xD1, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
2449                 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2450 let Uses = [CL] in {
2451 def RCR16rCL : I<0xD3, MRM3r, (outs GR16:$dst), (ins GR16:$src1),
2452                  "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2453 }
2454 def RCR16ri : Ii8<0xC1, MRM3r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$cnt),
2455                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2456
2457 def RCR32r1 : I<0xD1, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
2458                 "rcr{l}\t{1, $dst|$dst, 1}", []>;
2459 let Uses = [CL] in {
2460 def RCR32rCL : I<0xD3, MRM3r, (outs GR32:$dst), (ins GR32:$src1),
2461                  "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
2462 }
2463 def RCR32ri : Ii8<0xC1, MRM3r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$cnt),
2464                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2465
2466 let Constraints = "" in {
2467 def RCL8m1 : I<0xD0, MRM2m, (outs), (ins i8mem:$dst),
2468                "rcl{b}\t{1, $dst|$dst, 1}", []>;
2469 def RCL8mi : Ii8<0xC0, MRM2m, (outs), (ins i8mem:$dst, i8imm:$cnt),
2470                  "rcl{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2471 def RCL16m1 : I<0xD1, MRM2m, (outs), (ins i16mem:$dst),
2472                 "rcl{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2473 def RCL16mi : Ii8<0xC1, MRM2m, (outs), (ins i16mem:$dst, i8imm:$cnt),
2474                   "rcl{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2475 def RCL32m1 : I<0xD1, MRM2m, (outs), (ins i32mem:$dst),
2476                 "rcl{l}\t{1, $dst|$dst, 1}", []>;
2477 def RCL32mi : Ii8<0xC1, MRM2m, (outs), (ins i32mem:$dst, i8imm:$cnt),
2478                   "rcl{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2479 def RCR8m1 : I<0xD0, MRM3m, (outs), (ins i8mem:$dst),
2480                "rcr{b}\t{1, $dst|$dst, 1}", []>;
2481 def RCR8mi : Ii8<0xC0, MRM3m, (outs), (ins i8mem:$dst, i8imm:$cnt),
2482                  "rcr{b}\t{$cnt, $dst|$dst, $cnt}", []>;
2483 def RCR16m1 : I<0xD1, MRM3m, (outs), (ins i16mem:$dst),
2484                 "rcr{w}\t{1, $dst|$dst, 1}", []>, OpSize;
2485 def RCR16mi : Ii8<0xC1, MRM3m, (outs), (ins i16mem:$dst, i8imm:$cnt),
2486                   "rcr{w}\t{$cnt, $dst|$dst, $cnt}", []>, OpSize;
2487 def RCR32m1 : I<0xD1, MRM3m, (outs), (ins i32mem:$dst),
2488                 "rcr{l}\t{1, $dst|$dst, 1}", []>;
2489 def RCR32mi : Ii8<0xC1, MRM3m, (outs), (ins i32mem:$dst, i8imm:$cnt),
2490                   "rcr{l}\t{$cnt, $dst|$dst, $cnt}", []>;
2491
2492 let Uses = [CL] in {
2493 def RCL8mCL : I<0xD2, MRM2m, (outs), (ins i8mem:$dst),
2494                 "rcl{b}\t{%cl, $dst|$dst, CL}", []>;
2495 def RCL16mCL : I<0xD3, MRM2m, (outs), (ins i16mem:$dst),
2496                  "rcl{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2497 def RCL32mCL : I<0xD3, MRM2m, (outs), (ins i32mem:$dst),
2498                  "rcl{l}\t{%cl, $dst|$dst, CL}", []>;
2499 def RCR8mCL : I<0xD2, MRM3m, (outs), (ins i8mem:$dst),
2500                 "rcr{b}\t{%cl, $dst|$dst, CL}", []>;
2501 def RCR16mCL : I<0xD3, MRM3m, (outs), (ins i16mem:$dst),
2502                  "rcr{w}\t{%cl, $dst|$dst, CL}", []>, OpSize;
2503 def RCR32mCL : I<0xD3, MRM3m, (outs), (ins i32mem:$dst),
2504                  "rcr{l}\t{%cl, $dst|$dst, CL}", []>;
2505 }
2506 } // Constraints = ""
2507
2508 // FIXME: provide shorter instructions when imm8 == 1
2509 let Uses = [CL] in {
2510 def ROL8rCL  : I<0xD2, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
2511                  "rol{b}\t{%cl, $dst|$dst, CL}",
2512                  [(set GR8:$dst, (rotl GR8:$src1, CL))]>;
2513 def ROL16rCL : I<0xD3, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
2514                  "rol{w}\t{%cl, $dst|$dst, CL}",
2515                  [(set GR16:$dst, (rotl GR16:$src1, CL))]>, OpSize;
2516 def ROL32rCL : I<0xD3, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
2517                  "rol{l}\t{%cl, $dst|$dst, CL}",
2518                  [(set GR32:$dst, (rotl GR32:$src1, CL))]>;
2519 }
2520
2521 def ROL8ri   : Ii8<0xC0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2522                    "rol{b}\t{$src2, $dst|$dst, $src2}",
2523                    [(set GR8:$dst, (rotl GR8:$src1, (i8 imm:$src2)))]>;
2524 def ROL16ri  : Ii8<0xC1, MRM0r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2525                    "rol{w}\t{$src2, $dst|$dst, $src2}",
2526                    [(set GR16:$dst, (rotl GR16:$src1, (i8 imm:$src2)))]>, 
2527                    OpSize;
2528 def ROL32ri  : Ii8<0xC1, MRM0r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2529                    "rol{l}\t{$src2, $dst|$dst, $src2}",
2530                    [(set GR32:$dst, (rotl GR32:$src1, (i8 imm:$src2)))]>;
2531
2532 // Rotate by 1
2533 def ROL8r1   : I<0xD0, MRM0r, (outs GR8 :$dst), (ins GR8 :$src1),
2534                  "rol{b}\t$dst",
2535                  [(set GR8:$dst, (rotl GR8:$src1, (i8 1)))]>;
2536 def ROL16r1  : I<0xD1, MRM0r, (outs GR16:$dst), (ins GR16:$src1),
2537                  "rol{w}\t$dst",
2538                  [(set GR16:$dst, (rotl GR16:$src1, (i8 1)))]>, OpSize;
2539 def ROL32r1  : I<0xD1, MRM0r, (outs GR32:$dst), (ins GR32:$src1),
2540                  "rol{l}\t$dst",
2541                  [(set GR32:$dst, (rotl GR32:$src1, (i8 1)))]>;
2542
2543 let Constraints = "" in {
2544   let Uses = [CL] in {
2545   def ROL8mCL  : I<0xD2, MRM0m, (outs), (ins i8mem :$dst),
2546                    "rol{b}\t{%cl, $dst|$dst, CL}",
2547                    [(store (rotl (loadi8 addr:$dst), CL), addr:$dst)]>;
2548   def ROL16mCL : I<0xD3, MRM0m, (outs), (ins i16mem:$dst),
2549                    "rol{w}\t{%cl, $dst|$dst, CL}",
2550                    [(store (rotl (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2551   def ROL32mCL : I<0xD3, MRM0m, (outs), (ins i32mem:$dst),
2552                    "rol{l}\t{%cl, $dst|$dst, CL}",
2553                    [(store (rotl (loadi32 addr:$dst), CL), addr:$dst)]>;
2554   }
2555   def ROL8mi   : Ii8<0xC0, MRM0m, (outs), (ins i8mem :$dst, i8imm:$src),
2556                      "rol{b}\t{$src, $dst|$dst, $src}",
2557                  [(store (rotl (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2558   def ROL16mi  : Ii8<0xC1, MRM0m, (outs), (ins i16mem:$dst, i8imm:$src),
2559                      "rol{w}\t{$src, $dst|$dst, $src}",
2560                 [(store (rotl (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2561                      OpSize;
2562   def ROL32mi  : Ii8<0xC1, MRM0m, (outs), (ins i32mem:$dst, i8imm:$src),
2563                      "rol{l}\t{$src, $dst|$dst, $src}",
2564                 [(store (rotl (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2565
2566   // Rotate by 1
2567   def ROL8m1   : I<0xD0, MRM0m, (outs), (ins i8mem :$dst),
2568                    "rol{b}\t$dst",
2569                  [(store (rotl (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2570   def ROL16m1  : I<0xD1, MRM0m, (outs), (ins i16mem:$dst),
2571                    "rol{w}\t$dst",
2572                 [(store (rotl (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2573                      OpSize;
2574   def ROL32m1  : I<0xD1, MRM0m, (outs), (ins i32mem:$dst),
2575                    "rol{l}\t$dst",
2576                 [(store (rotl (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2577 } // Constraints = ""
2578
2579 let Uses = [CL] in {
2580 def ROR8rCL  : I<0xD2, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
2581                  "ror{b}\t{%cl, $dst|$dst, CL}",
2582                  [(set GR8:$dst, (rotr GR8:$src1, CL))]>;
2583 def ROR16rCL : I<0xD3, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
2584                  "ror{w}\t{%cl, $dst|$dst, CL}",
2585                  [(set GR16:$dst, (rotr GR16:$src1, CL))]>, OpSize;
2586 def ROR32rCL : I<0xD3, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
2587                  "ror{l}\t{%cl, $dst|$dst, CL}",
2588                  [(set GR32:$dst, (rotr GR32:$src1, CL))]>;
2589 }
2590
2591 def ROR8ri   : Ii8<0xC0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1, i8imm:$src2),
2592                    "ror{b}\t{$src2, $dst|$dst, $src2}",
2593                    [(set GR8:$dst, (rotr GR8:$src1, (i8 imm:$src2)))]>;
2594 def ROR16ri  : Ii8<0xC1, MRM1r, (outs GR16:$dst), (ins GR16:$src1, i8imm:$src2),
2595                    "ror{w}\t{$src2, $dst|$dst, $src2}",
2596                    [(set GR16:$dst, (rotr GR16:$src1, (i8 imm:$src2)))]>, 
2597                    OpSize;
2598 def ROR32ri  : Ii8<0xC1, MRM1r, (outs GR32:$dst), (ins GR32:$src1, i8imm:$src2),
2599                    "ror{l}\t{$src2, $dst|$dst, $src2}",
2600                    [(set GR32:$dst, (rotr GR32:$src1, (i8 imm:$src2)))]>;
2601
2602 // Rotate by 1
2603 def ROR8r1   : I<0xD0, MRM1r, (outs GR8 :$dst), (ins GR8 :$src1),
2604                  "ror{b}\t$dst",
2605                  [(set GR8:$dst, (rotr GR8:$src1, (i8 1)))]>;
2606 def ROR16r1  : I<0xD1, MRM1r, (outs GR16:$dst), (ins GR16:$src1),
2607                  "ror{w}\t$dst",
2608                  [(set GR16:$dst, (rotr GR16:$src1, (i8 1)))]>, OpSize;
2609 def ROR32r1  : I<0xD1, MRM1r, (outs GR32:$dst), (ins GR32:$src1),
2610                  "ror{l}\t$dst",
2611                  [(set GR32:$dst, (rotr GR32:$src1, (i8 1)))]>;
2612
2613 let Constraints = "" in {
2614   let Uses = [CL] in {
2615   def ROR8mCL  : I<0xD2, MRM1m, (outs), (ins i8mem :$dst),
2616                    "ror{b}\t{%cl, $dst|$dst, CL}",
2617                    [(store (rotr (loadi8 addr:$dst), CL), addr:$dst)]>;
2618   def ROR16mCL : I<0xD3, MRM1m, (outs), (ins i16mem:$dst),
2619                    "ror{w}\t{%cl, $dst|$dst, CL}",
2620                    [(store (rotr (loadi16 addr:$dst), CL), addr:$dst)]>, OpSize;
2621   def ROR32mCL : I<0xD3, MRM1m, (outs), (ins i32mem:$dst), 
2622                    "ror{l}\t{%cl, $dst|$dst, CL}",
2623                    [(store (rotr (loadi32 addr:$dst), CL), addr:$dst)]>;
2624   }
2625   def ROR8mi   : Ii8<0xC0, MRM1m, (outs), (ins i8mem :$dst, i8imm:$src),
2626                      "ror{b}\t{$src, $dst|$dst, $src}",
2627                  [(store (rotr (loadi8 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2628   def ROR16mi  : Ii8<0xC1, MRM1m, (outs), (ins i16mem:$dst, i8imm:$src),
2629                      "ror{w}\t{$src, $dst|$dst, $src}",
2630                 [(store (rotr (loadi16 addr:$dst), (i8 imm:$src)), addr:$dst)]>,
2631                      OpSize;
2632   def ROR32mi  : Ii8<0xC1, MRM1m, (outs), (ins i32mem:$dst, i8imm:$src),
2633                      "ror{l}\t{$src, $dst|$dst, $src}",
2634                 [(store (rotr (loadi32 addr:$dst), (i8 imm:$src)), addr:$dst)]>;
2635
2636   // Rotate by 1
2637   def ROR8m1   : I<0xD0, MRM1m, (outs), (ins i8mem :$dst),
2638                    "ror{b}\t$dst",
2639                  [(store (rotr (loadi8 addr:$dst), (i8 1)), addr:$dst)]>;
2640   def ROR16m1  : I<0xD1, MRM1m, (outs), (ins i16mem:$dst),
2641                    "ror{w}\t$dst",
2642                 [(store (rotr (loadi16 addr:$dst), (i8 1)), addr:$dst)]>,
2643                      OpSize;
2644   def ROR32m1  : I<0xD1, MRM1m, (outs), (ins i32mem:$dst),
2645                    "ror{l}\t$dst",
2646                 [(store (rotr (loadi32 addr:$dst), (i8 1)), addr:$dst)]>;
2647 } // Constraints = ""
2648
2649
2650 // Double shift instructions (generalizations of rotate)
2651 let Uses = [CL] in {
2652 def SHLD32rrCL : I<0xA5, MRMDestReg, (outs GR32:$dst), 
2653                    (ins GR32:$src1, GR32:$src2),
2654                    "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2655                    [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2, CL))]>, TB;
2656 def SHRD32rrCL : I<0xAD, MRMDestReg, (outs GR32:$dst),
2657                    (ins GR32:$src1, GR32:$src2),
2658                    "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2659                    [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2, CL))]>, TB;
2660 def SHLD16rrCL : I<0xA5, MRMDestReg, (outs GR16:$dst), 
2661                    (ins GR16:$src1, GR16:$src2),
2662                    "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2663                    [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2, CL))]>,
2664                    TB, OpSize;
2665 def SHRD16rrCL : I<0xAD, MRMDestReg, (outs GR16:$dst), 
2666                    (ins GR16:$src1, GR16:$src2),
2667                    "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2668                    [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2, CL))]>,
2669                    TB, OpSize;
2670 }
2671
2672 let isCommutable = 1 in {  // These instructions commute to each other.
2673 def SHLD32rri8 : Ii8<0xA4, MRMDestReg,
2674                      (outs GR32:$dst), 
2675                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
2676                      "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2677                      [(set GR32:$dst, (X86shld GR32:$src1, GR32:$src2,
2678                                       (i8 imm:$src3)))]>,
2679                  TB;
2680 def SHRD32rri8 : Ii8<0xAC, MRMDestReg,
2681                      (outs GR32:$dst), 
2682                      (ins GR32:$src1, GR32:$src2, i8imm:$src3),
2683                      "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2684                      [(set GR32:$dst, (X86shrd GR32:$src1, GR32:$src2,
2685                                       (i8 imm:$src3)))]>,
2686                  TB;
2687 def SHLD16rri8 : Ii8<0xA4, MRMDestReg,
2688                      (outs GR16:$dst), 
2689                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
2690                      "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2691                      [(set GR16:$dst, (X86shld GR16:$src1, GR16:$src2,
2692                                       (i8 imm:$src3)))]>,
2693                      TB, OpSize;
2694 def SHRD16rri8 : Ii8<0xAC, MRMDestReg,
2695                      (outs GR16:$dst), 
2696                      (ins GR16:$src1, GR16:$src2, i8imm:$src3),
2697                      "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2698                      [(set GR16:$dst, (X86shrd GR16:$src1, GR16:$src2,
2699                                       (i8 imm:$src3)))]>,
2700                      TB, OpSize;
2701 }
2702
2703 let Constraints = "" in {
2704   let Uses = [CL] in {
2705   def SHLD32mrCL : I<0xA5, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2706                      "shld{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2707                      [(store (X86shld (loadi32 addr:$dst), GR32:$src2, CL),
2708                        addr:$dst)]>, TB;
2709   def SHRD32mrCL : I<0xAD, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2710                     "shrd{l}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2711                     [(store (X86shrd (loadi32 addr:$dst), GR32:$src2, CL),
2712                       addr:$dst)]>, TB;
2713   }
2714   def SHLD32mri8 : Ii8<0xA4, MRMDestMem,
2715                       (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
2716                       "shld{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2717                       [(store (X86shld (loadi32 addr:$dst), GR32:$src2,
2718                                         (i8 imm:$src3)), addr:$dst)]>,
2719                       TB;
2720   def SHRD32mri8 : Ii8<0xAC, MRMDestMem, 
2721                        (outs), (ins i32mem:$dst, GR32:$src2, i8imm:$src3),
2722                        "shrd{l}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2723                        [(store (X86shrd (loadi32 addr:$dst), GR32:$src2,
2724                                          (i8 imm:$src3)), addr:$dst)]>,
2725                        TB;
2726
2727   let Uses = [CL] in {
2728   def SHLD16mrCL : I<0xA5, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2729                      "shld{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2730                      [(store (X86shld (loadi16 addr:$dst), GR16:$src2, CL),
2731                        addr:$dst)]>, TB, OpSize;
2732   def SHRD16mrCL : I<0xAD, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2733                     "shrd{w}\t{%cl, $src2, $dst|$dst, $src2, CL}",
2734                     [(store (X86shrd (loadi16 addr:$dst), GR16:$src2, CL),
2735                       addr:$dst)]>, TB, OpSize;
2736   }
2737   def SHLD16mri8 : Ii8<0xA4, MRMDestMem,
2738                       (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
2739                       "shld{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2740                       [(store (X86shld (loadi16 addr:$dst), GR16:$src2,
2741                                         (i8 imm:$src3)), addr:$dst)]>,
2742                       TB, OpSize;
2743   def SHRD16mri8 : Ii8<0xAC, MRMDestMem, 
2744                        (outs), (ins i16mem:$dst, GR16:$src2, i8imm:$src3),
2745                        "shrd{w}\t{$src3, $src2, $dst|$dst, $src2, $src3}",
2746                       [(store (X86shrd (loadi16 addr:$dst), GR16:$src2,
2747                                         (i8 imm:$src3)), addr:$dst)]>,
2748                        TB, OpSize;
2749 } // Constraints = ""
2750 } // Defs = [EFLAGS]
2751
2752
2753 // Arithmetic.
2754 let Defs = [EFLAGS] in {
2755 let isCommutable = 1 in {   // X = ADD Y, Z   --> X = ADD Z, Y
2756 // Register-Register Addition
2757 def ADD8rr    : I<0x00, MRMDestReg, (outs GR8 :$dst),
2758                                     (ins GR8 :$src1, GR8 :$src2),
2759                   "add{b}\t{$src2, $dst|$dst, $src2}",
2760                   [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1, GR8:$src2))]>;
2761
2762 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2763 // Register-Register Addition
2764 def ADD16rr  : I<0x01, MRMDestReg, (outs GR16:$dst),
2765                                    (ins GR16:$src1, GR16:$src2),
2766                  "add{w}\t{$src2, $dst|$dst, $src2}",
2767                  [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2768                                                        GR16:$src2))]>, OpSize;
2769 def ADD32rr  : I<0x01, MRMDestReg, (outs GR32:$dst),
2770                                    (ins GR32:$src1, GR32:$src2),
2771                  "add{l}\t{$src2, $dst|$dst, $src2}",
2772                  [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2773                                                        GR32:$src2))]>;
2774 } // end isConvertibleToThreeAddress
2775 } // end isCommutable
2776
2777 // These are alternate spellings for use by the disassembler, we mark them as
2778 // code gen only to ensure they aren't matched by the assembler.
2779 let isCodeGenOnly = 1 in {
2780   def ADD8rr_alt: I<0x02, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2781                    "add{b}\t{$src2, $dst|$dst, $src2}", []>;
2782   def ADD16rr_alt: I<0x03, MRMSrcReg,(outs GR16:$dst),(ins GR16:$src1, GR16:$src2),
2783                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2784   def ADD32rr_alt: I<0x03, MRMSrcReg,(outs GR32:$dst),(ins GR32:$src1, GR32:$src2),
2785                     "add{l}\t{$src2, $dst|$dst, $src2}", []>;
2786 }
2787
2788 // Register-Memory Addition
2789 def ADD8rm   : I<0x02, MRMSrcMem, (outs GR8 :$dst),
2790                                   (ins GR8 :$src1, i8mem :$src2),
2791                  "add{b}\t{$src2, $dst|$dst, $src2}",
2792                  [(set GR8:$dst, EFLAGS, (X86add_flag GR8:$src1,
2793                                                       (load addr:$src2)))]>;
2794 def ADD16rm  : I<0x03, MRMSrcMem, (outs GR16:$dst),
2795                                   (ins GR16:$src1, i16mem:$src2),
2796                  "add{w}\t{$src2, $dst|$dst, $src2}",
2797                  [(set GR16:$dst, EFLAGS, (X86add_flag GR16:$src1,
2798                                                   (load addr:$src2)))]>, OpSize;
2799 def ADD32rm  : I<0x03, MRMSrcMem, (outs GR32:$dst),
2800                                   (ins GR32:$src1, i32mem:$src2),
2801                  "add{l}\t{$src2, $dst|$dst, $src2}",
2802                  [(set GR32:$dst, EFLAGS, (X86add_flag GR32:$src1,
2803                                                        (load addr:$src2)))]>;
2804                   
2805 // Register-Integer Addition
2806 def ADD8ri    : Ii8<0x80, MRM0r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2807                     "add{b}\t{$src2, $dst|$dst, $src2}",
2808                     [(set GR8:$dst, EFLAGS,
2809                           (X86add_flag GR8:$src1, imm:$src2))]>;
2810
2811 let isConvertibleToThreeAddress = 1 in {   // Can transform into LEA.
2812 // Register-Integer Addition
2813 def ADD16ri  : Ii16<0x81, MRM0r, (outs GR16:$dst),
2814                                  (ins GR16:$src1, i16imm:$src2),
2815                     "add{w}\t{$src2, $dst|$dst, $src2}",
2816                     [(set GR16:$dst, EFLAGS,
2817                           (X86add_flag GR16:$src1, imm:$src2))]>, OpSize;
2818 def ADD32ri  : Ii32<0x81, MRM0r, (outs GR32:$dst),
2819                                  (ins GR32:$src1, i32imm:$src2),
2820                     "add{l}\t{$src2, $dst|$dst, $src2}",
2821                     [(set GR32:$dst, EFLAGS, 
2822                           (X86add_flag GR32:$src1, imm:$src2))]>;
2823 def ADD16ri8 : Ii8<0x83, MRM0r, (outs GR16:$dst),
2824                                 (ins GR16:$src1, i16i8imm:$src2),
2825                    "add{w}\t{$src2, $dst|$dst, $src2}",
2826                    [(set GR16:$dst, EFLAGS,
2827                          (X86add_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
2828 def ADD32ri8 : Ii8<0x83, MRM0r, (outs GR32:$dst),
2829                                 (ins GR32:$src1, i32i8imm:$src2),
2830                    "add{l}\t{$src2, $dst|$dst, $src2}",
2831                    [(set GR32:$dst, EFLAGS,
2832                          (X86add_flag GR32:$src1, i32immSExt8:$src2))]>;
2833 }
2834
2835 let Constraints = "" in {
2836   // Memory-Register Addition
2837   def ADD8mr   : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2838                    "add{b}\t{$src2, $dst|$dst, $src2}",
2839                    [(store (add (load addr:$dst), GR8:$src2), addr:$dst),
2840                     (implicit EFLAGS)]>;
2841   def ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2842                    "add{w}\t{$src2, $dst|$dst, $src2}",
2843                    [(store (add (load addr:$dst), GR16:$src2), addr:$dst),
2844                     (implicit EFLAGS)]>, OpSize;
2845   def ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2846                    "add{l}\t{$src2, $dst|$dst, $src2}",
2847                    [(store (add (load addr:$dst), GR32:$src2), addr:$dst),
2848                     (implicit EFLAGS)]>;
2849   def ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
2850                      "add{b}\t{$src2, $dst|$dst, $src2}",
2851                    [(store (add (loadi8 addr:$dst), imm:$src2), addr:$dst),
2852                     (implicit EFLAGS)]>;
2853   def ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
2854                       "add{w}\t{$src2, $dst|$dst, $src2}",
2855                   [(store (add (loadi16 addr:$dst), imm:$src2), addr:$dst),
2856                    (implicit EFLAGS)]>, OpSize;
2857   def ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
2858                       "add{l}\t{$src2, $dst|$dst, $src2}",
2859                       [(store (add (loadi32 addr:$dst), imm:$src2), addr:$dst),
2860                        (implicit EFLAGS)]>;
2861   def ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2862                      "add{w}\t{$src2, $dst|$dst, $src2}",
2863                      [(store (add (load addr:$dst), i16immSExt8:$src2),
2864                                   addr:$dst),
2865                       (implicit EFLAGS)]>, OpSize;
2866   def ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2867                      "add{l}\t{$src2, $dst|$dst, $src2}",
2868                   [(store (add (load addr:$dst), i32immSExt8:$src2),
2869                                addr:$dst),
2870                    (implicit EFLAGS)]>;
2871
2872   // addition to rAX
2873   def ADD8i8 : Ii8<0x04, RawFrm, (outs), (ins i8imm:$src),
2874                    "add{b}\t{$src, %al|%al, $src}", []>;
2875   def ADD16i16 : Ii16<0x05, RawFrm, (outs), (ins i16imm:$src),
2876                       "add{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2877   def ADD32i32 : Ii32<0x05, RawFrm, (outs), (ins i32imm:$src),
2878                       "add{l}\t{$src, %eax|%eax, $src}", []>;
2879 } // Constraints = ""
2880
2881 let Uses = [EFLAGS] in {
2882 let isCommutable = 1 in {  // X = ADC Y, Z --> X = ADC Z, Y
2883 def ADC8rr   : I<0x10, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2884                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2885                  [(set GR8:$dst, (adde GR8:$src1, GR8:$src2))]>;
2886 def ADC16rr  : I<0x11, MRMDestReg, (outs GR16:$dst),
2887                                    (ins GR16:$src1, GR16:$src2),
2888                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2889                  [(set GR16:$dst, (adde GR16:$src1, GR16:$src2))]>, OpSize;
2890 def ADC32rr  : I<0x11, MRMDestReg, (outs GR32:$dst),
2891                                    (ins GR32:$src1, GR32:$src2),
2892                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2893                  [(set GR32:$dst, (adde GR32:$src1, GR32:$src2))]>;
2894 }
2895
2896 let isCodeGenOnly = 1 in {
2897 def ADC8rr_REV : I<0x12, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2898                  "adc{b}\t{$src2, $dst|$dst, $src2}", []>;
2899 def ADC16rr_REV : I<0x13, MRMSrcReg, (outs GR16:$dst), 
2900                     (ins GR16:$src1, GR16:$src2),
2901                     "adc{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2902 def ADC32rr_REV : I<0x13, MRMSrcReg, (outs GR32:$dst), 
2903                     (ins GR32:$src1, GR32:$src2),
2904                     "adc{l}\t{$src2, $dst|$dst, $src2}", []>;
2905 }
2906
2907 def ADC8rm   : I<0x12, MRMSrcMem , (outs GR8:$dst), 
2908                                    (ins GR8:$src1, i8mem:$src2),
2909                  "adc{b}\t{$src2, $dst|$dst, $src2}",
2910                  [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2)))]>;
2911 def ADC16rm  : I<0x13, MRMSrcMem , (outs GR16:$dst),
2912                                    (ins GR16:$src1, i16mem:$src2),
2913                  "adc{w}\t{$src2, $dst|$dst, $src2}",
2914                  [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2)))]>,
2915                  OpSize;
2916 def ADC32rm  : I<0x13, MRMSrcMem , (outs GR32:$dst),
2917                                    (ins GR32:$src1, i32mem:$src2),
2918                  "adc{l}\t{$src2, $dst|$dst, $src2}",
2919                  [(set GR32:$dst, (adde GR32:$src1, (load addr:$src2)))]>;
2920 def ADC8ri   : Ii8<0x80, MRM2r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
2921                     "adc{b}\t{$src2, $dst|$dst, $src2}",
2922                  [(set GR8:$dst, (adde GR8:$src1, imm:$src2))]>;
2923 def ADC16ri  : Ii16<0x81, MRM2r, (outs GR16:$dst),
2924                                  (ins GR16:$src1, i16imm:$src2),
2925                     "adc{w}\t{$src2, $dst|$dst, $src2}",
2926                  [(set GR16:$dst, (adde GR16:$src1, imm:$src2))]>, OpSize;
2927 def ADC16ri8 : Ii8<0x83, MRM2r, (outs GR16:$dst),
2928                                 (ins GR16:$src1, i16i8imm:$src2),
2929                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2930                  [(set GR16:$dst, (adde GR16:$src1, i16immSExt8:$src2))]>,
2931                  OpSize;
2932 def ADC32ri  : Ii32<0x81, MRM2r, (outs GR32:$dst),
2933                                  (ins GR32:$src1, i32imm:$src2),
2934                     "adc{l}\t{$src2, $dst|$dst, $src2}",
2935                  [(set GR32:$dst, (adde GR32:$src1, imm:$src2))]>;
2936 def ADC32ri8 : Ii8<0x83, MRM2r, (outs GR32:$dst),
2937                                 (ins GR32:$src1, i32i8imm:$src2),
2938                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2939                  [(set GR32:$dst, (adde GR32:$src1, i32immSExt8:$src2))]>;
2940
2941 let Constraints = "" in {
2942   def ADC8mr   : I<0x10, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
2943                    "adc{b}\t{$src2, $dst|$dst, $src2}",
2944                    [(store (adde (load addr:$dst), GR8:$src2), addr:$dst)]>;
2945   def ADC16mr  : I<0x11, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
2946                    "adc{w}\t{$src2, $dst|$dst, $src2}",
2947                    [(store (adde (load addr:$dst), GR16:$src2), addr:$dst)]>,
2948                    OpSize;
2949   def ADC32mr  : I<0x11, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
2950                    "adc{l}\t{$src2, $dst|$dst, $src2}",
2951                    [(store (adde (load addr:$dst), GR32:$src2), addr:$dst)]>;
2952   def ADC8mi   : Ii8<0x80, MRM2m, (outs), (ins i8mem:$dst, i8imm:$src2),
2953                       "adc{b}\t{$src2, $dst|$dst, $src2}",
2954                   [(store (adde (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
2955   def ADC16mi  : Ii16<0x81, MRM2m, (outs), (ins i16mem:$dst, i16imm:$src2),
2956                       "adc{w}\t{$src2, $dst|$dst, $src2}",
2957                   [(store (adde (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
2958                   OpSize;
2959   def ADC16mi8 : Ii8<0x83, MRM2m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
2960                      "adc{w}\t{$src2, $dst|$dst, $src2}",
2961                [(store (adde (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
2962                OpSize;
2963   def ADC32mi  : Ii32<0x81, MRM2m, (outs), (ins i32mem:$dst, i32imm:$src2),
2964                       "adc{l}\t{$src2, $dst|$dst, $src2}",
2965                   [(store (adde (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
2966   def ADC32mi8 : Ii8<0x83, MRM2m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
2967                      "adc{l}\t{$src2, $dst|$dst, $src2}",
2968                [(store (adde (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
2969
2970   def ADC8i8 : Ii8<0x14, RawFrm, (outs), (ins i8imm:$src),
2971                    "adc{b}\t{$src, %al|%al, $src}", []>;
2972   def ADC16i16 : Ii16<0x15, RawFrm, (outs), (ins i16imm:$src),
2973                       "adc{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
2974   def ADC32i32 : Ii32<0x15, RawFrm, (outs), (ins i32imm:$src),
2975                       "adc{l}\t{$src, %eax|%eax, $src}", []>;
2976 } // Constraints = ""
2977 } // Uses = [EFLAGS]
2978
2979 // Register-Register Subtraction
2980 def SUB8rr  : I<0x28, MRMDestReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2981                 "sub{b}\t{$src2, $dst|$dst, $src2}",
2982                 [(set GR8:$dst, EFLAGS,
2983                       (X86sub_flag GR8:$src1, GR8:$src2))]>;
2984 def SUB16rr : I<0x29, MRMDestReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
2985                 "sub{w}\t{$src2, $dst|$dst, $src2}",
2986                 [(set GR16:$dst, EFLAGS,
2987                       (X86sub_flag GR16:$src1, GR16:$src2))]>, OpSize;
2988 def SUB32rr : I<0x29, MRMDestReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
2989                 "sub{l}\t{$src2, $dst|$dst, $src2}",
2990                 [(set GR32:$dst, EFLAGS,
2991                       (X86sub_flag GR32:$src1, GR32:$src2))]>;
2992
2993 let isCodeGenOnly = 1 in {
2994 def SUB8rr_REV : I<0x2A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
2995                    "sub{b}\t{$src2, $dst|$dst, $src2}", []>;
2996 def SUB16rr_REV : I<0x2B, MRMSrcReg, (outs GR16:$dst), 
2997                     (ins GR16:$src1, GR16:$src2),
2998                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
2999 def SUB32rr_REV : I<0x2B, MRMSrcReg, (outs GR32:$dst), 
3000                     (ins GR32:$src1, GR32:$src2),
3001                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>;
3002 }
3003
3004 // Register-Memory Subtraction
3005 def SUB8rm  : I<0x2A, MRMSrcMem, (outs GR8 :$dst),
3006                                  (ins GR8 :$src1, i8mem :$src2),
3007                 "sub{b}\t{$src2, $dst|$dst, $src2}",
3008                 [(set GR8:$dst, EFLAGS,
3009                       (X86sub_flag GR8:$src1, (load addr:$src2)))]>;
3010 def SUB16rm : I<0x2B, MRMSrcMem, (outs GR16:$dst),
3011                                  (ins GR16:$src1, i16mem:$src2),
3012                 "sub{w}\t{$src2, $dst|$dst, $src2}",
3013                 [(set GR16:$dst, EFLAGS,
3014                       (X86sub_flag GR16:$src1, (load addr:$src2)))]>, OpSize;
3015 def SUB32rm : I<0x2B, MRMSrcMem, (outs GR32:$dst),
3016                                  (ins GR32:$src1, i32mem:$src2),
3017                 "sub{l}\t{$src2, $dst|$dst, $src2}",
3018                 [(set GR32:$dst, EFLAGS,
3019                       (X86sub_flag GR32:$src1, (load addr:$src2)))]>;
3020
3021 // Register-Integer Subtraction
3022 def SUB8ri   : Ii8 <0x80, MRM5r, (outs GR8:$dst),
3023                                  (ins GR8:$src1, i8imm:$src2),
3024                     "sub{b}\t{$src2, $dst|$dst, $src2}",
3025                     [(set GR8:$dst, EFLAGS,
3026                           (X86sub_flag GR8:$src1, imm:$src2))]>;
3027 def SUB16ri  : Ii16<0x81, MRM5r, (outs GR16:$dst),
3028                                  (ins GR16:$src1, i16imm:$src2),
3029                     "sub{w}\t{$src2, $dst|$dst, $src2}",
3030                     [(set GR16:$dst, EFLAGS,
3031                           (X86sub_flag GR16:$src1, imm:$src2))]>, OpSize;
3032 def SUB32ri  : Ii32<0x81, MRM5r, (outs GR32:$dst),
3033                                  (ins GR32:$src1, i32imm:$src2),
3034                     "sub{l}\t{$src2, $dst|$dst, $src2}",
3035                     [(set GR32:$dst, EFLAGS,
3036                           (X86sub_flag GR32:$src1, imm:$src2))]>;
3037 def SUB16ri8 : Ii8<0x83, MRM5r, (outs GR16:$dst),
3038                                 (ins GR16:$src1, i16i8imm:$src2),
3039                    "sub{w}\t{$src2, $dst|$dst, $src2}",
3040                    [(set GR16:$dst, EFLAGS,
3041                          (X86sub_flag GR16:$src1, i16immSExt8:$src2))]>, OpSize;
3042 def SUB32ri8 : Ii8<0x83, MRM5r, (outs GR32:$dst),
3043                                 (ins GR32:$src1, i32i8imm:$src2),
3044                    "sub{l}\t{$src2, $dst|$dst, $src2}",
3045                    [(set GR32:$dst, EFLAGS,
3046                          (X86sub_flag GR32:$src1, i32immSExt8:$src2))]>;
3047
3048 let Constraints = "" in {
3049   // Memory-Register Subtraction
3050   def SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
3051                    "sub{b}\t{$src2, $dst|$dst, $src2}",
3052                    [(store (sub (load addr:$dst), GR8:$src2), addr:$dst),
3053                     (implicit EFLAGS)]>;
3054   def SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
3055                    "sub{w}\t{$src2, $dst|$dst, $src2}",
3056                    [(store (sub (load addr:$dst), GR16:$src2), addr:$dst),
3057                     (implicit EFLAGS)]>, OpSize;
3058   def SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
3059                    "sub{l}\t{$src2, $dst|$dst, $src2}",
3060                    [(store (sub (load addr:$dst), GR32:$src2), addr:$dst),
3061                     (implicit EFLAGS)]>;
3062
3063   // Memory-Integer Subtraction
3064   def SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
3065                      "sub{b}\t{$src2, $dst|$dst, $src2}",
3066                      [(store (sub (loadi8 addr:$dst), imm:$src2), addr:$dst),
3067                       (implicit EFLAGS)]>;
3068   def SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
3069                       "sub{w}\t{$src2, $dst|$dst, $src2}",
3070                       [(store (sub (loadi16 addr:$dst), imm:$src2),addr:$dst),
3071                        (implicit EFLAGS)]>, OpSize;
3072   def SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
3073                       "sub{l}\t{$src2, $dst|$dst, $src2}",
3074                       [(store (sub (loadi32 addr:$dst), imm:$src2),addr:$dst),
3075                        (implicit EFLAGS)]>;
3076   def SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
3077                      "sub{w}\t{$src2, $dst|$dst, $src2}",
3078                      [(store (sub (load addr:$dst), i16immSExt8:$src2),
3079                              addr:$dst),
3080                       (implicit EFLAGS)]>, OpSize;
3081   def SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
3082                      "sub{l}\t{$src2, $dst|$dst, $src2}",
3083                      [(store (sub (load addr:$dst), i32immSExt8:$src2),
3084                              addr:$dst),
3085                       (implicit EFLAGS)]>;
3086                       
3087   def SUB8i8 : Ii8<0x2C, RawFrm, (outs), (ins i8imm:$src),
3088                    "sub{b}\t{$src, %al|%al, $src}", []>;
3089   def SUB16i16 : Ii16<0x2D, RawFrm, (outs), (ins i16imm:$src),
3090                       "sub{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3091   def SUB32i32 : Ii32<0x2D, RawFrm, (outs), (ins i32imm:$src),
3092                       "sub{l}\t{$src, %eax|%eax, $src}", []>;
3093 } // Constraints = ""
3094
3095 let Uses = [EFLAGS] in {
3096 def SBB8rr     : I<0x18, MRMDestReg, (outs GR8:$dst),
3097                                      (ins GR8:$src1, GR8:$src2),
3098                   "sbb{b}\t{$src2, $dst|$dst, $src2}",
3099                  [(set GR8:$dst, (sube GR8:$src1, GR8:$src2))]>;
3100 def SBB16rr    : I<0x19, MRMDestReg, (outs GR16:$dst),
3101                                      (ins GR16:$src1, GR16:$src2),
3102                   "sbb{w}\t{$src2, $dst|$dst, $src2}",
3103                  [(set GR16:$dst, (sube GR16:$src1, GR16:$src2))]>, OpSize;
3104 def SBB32rr    : I<0x19, MRMDestReg, (outs GR32:$dst),
3105                                       (ins GR32:$src1, GR32:$src2),
3106                   "sbb{l}\t{$src2, $dst|$dst, $src2}",
3107                  [(set GR32:$dst, (sube GR32:$src1, GR32:$src2))]>;
3108
3109 let Constraints = "" in {
3110   def SBB8mr   : I<0x18, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2), 
3111                    "sbb{b}\t{$src2, $dst|$dst, $src2}",
3112                    [(store (sube (load addr:$dst), GR8:$src2), addr:$dst)]>;
3113   def SBB16mr  : I<0x19, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2), 
3114                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
3115                    [(store (sube (load addr:$dst), GR16:$src2), addr:$dst)]>,
3116                    OpSize;
3117   def SBB32mr  : I<0x19, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
3118                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
3119                    [(store (sube (load addr:$dst), GR32:$src2), addr:$dst)]>;
3120   def SBB8mi  : Ii8<0x80, MRM3m, (outs), (ins i8mem:$dst, i8imm:$src2), 
3121                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
3122                    [(store (sube (loadi8 addr:$dst), imm:$src2), addr:$dst)]>;
3123   def SBB16mi  : Ii16<0x81, MRM3m, (outs), (ins i16mem:$dst, i16imm:$src2), 
3124                       "sbb{w}\t{$src2, $dst|$dst, $src2}",
3125                   [(store (sube (loadi16 addr:$dst), imm:$src2), addr:$dst)]>,
3126                   OpSize;
3127   def SBB16mi8 : Ii8<0x83, MRM3m, (outs), (ins i16mem:$dst, i16i8imm :$src2), 
3128                      "sbb{w}\t{$src2, $dst|$dst, $src2}",
3129                [(store (sube (load addr:$dst), i16immSExt8:$src2), addr:$dst)]>,
3130                OpSize;
3131   def SBB32mi  : Ii32<0x81, MRM3m, (outs), (ins i32mem:$dst, i32imm:$src2), 
3132                       "sbb{l}\t{$src2, $dst|$dst, $src2}",
3133                   [(store (sube (loadi32 addr:$dst), imm:$src2), addr:$dst)]>;
3134   def SBB32mi8 : Ii8<0x83, MRM3m, (outs), (ins i32mem:$dst, i32i8imm :$src2), 
3135                      "sbb{l}\t{$src2, $dst|$dst, $src2}",
3136                [(store (sube (load addr:$dst), i32immSExt8:$src2), addr:$dst)]>;
3137                
3138   def SBB8i8 : Ii8<0x1C, RawFrm, (outs), (ins i8imm:$src),
3139                    "sbb{b}\t{$src, %al|%al, $src}", []>;
3140   def SBB16i16 : Ii16<0x1D, RawFrm, (outs), (ins i16imm:$src),
3141                       "sbb{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3142   def SBB32i32 : Ii32<0x1D, RawFrm, (outs), (ins i32imm:$src),
3143                       "sbb{l}\t{$src, %eax|%eax, $src}", []>;
3144 } // Constraints = ""
3145
3146 let isCodeGenOnly = 1 in {
3147 def SBB8rr_REV : I<0x1A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
3148                    "sbb{b}\t{$src2, $dst|$dst, $src2}", []>;
3149 def SBB16rr_REV : I<0x1B, MRMSrcReg, (outs GR16:$dst), 
3150                     (ins GR16:$src1, GR16:$src2),
3151                     "sbb{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize;
3152 def SBB32rr_REV : I<0x1B, MRMSrcReg, (outs GR32:$dst), 
3153                     (ins GR32:$src1, GR32:$src2),
3154                     "sbb{l}\t{$src2, $dst|$dst, $src2}", []>;
3155 }
3156
3157 def SBB8rm   : I<0x1A, MRMSrcMem, (outs GR8:$dst), (ins GR8:$src1, i8mem:$src2),
3158                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
3159                     [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2)))]>;
3160 def SBB16rm  : I<0x1B, MRMSrcMem, (outs GR16:$dst),
3161                                   (ins GR16:$src1, i16mem:$src2),
3162                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
3163                     [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2)))]>,
3164                     OpSize;
3165 def SBB32rm  : I<0x1B, MRMSrcMem, (outs GR32:$dst),
3166                                   (ins GR32:$src1, i32mem:$src2),
3167                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
3168                     [(set GR32:$dst, (sube GR32:$src1, (load addr:$src2)))]>;
3169 def SBB8ri   : Ii8<0x80, MRM3r, (outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
3170                     "sbb{b}\t{$src2, $dst|$dst, $src2}",
3171                     [(set GR8:$dst, (sube GR8:$src1, imm:$src2))]>;
3172 def SBB16ri  : Ii16<0x81, MRM3r, (outs GR16:$dst),
3173                                  (ins GR16:$src1, i16imm:$src2),
3174                     "sbb{w}\t{$src2, $dst|$dst, $src2}",
3175                     [(set GR16:$dst, (sube GR16:$src1, imm:$src2))]>, OpSize;
3176 def SBB16ri8 : Ii8<0x83, MRM3r, (outs GR16:$dst),
3177                                 (ins GR16:$src1, i16i8imm:$src2),
3178                    "sbb{w}\t{$src2, $dst|$dst, $src2}",
3179                    [(set GR16:$dst, (sube GR16:$src1, i16immSExt8:$src2))]>,
3180                    OpSize;
3181 def SBB32ri  : Ii32<0x81, MRM3r, (outs GR32:$dst), 
3182                                  (ins GR32:$src1, i32imm:$src2),
3183                     "sbb{l}\t{$src2, $dst|$dst, $src2}",
3184                     [(set GR32:$dst, (sube GR32:$src1, imm:$src2))]>;
3185 def SBB32ri8 : Ii8<0x83, MRM3r, (outs GR32:$dst),
3186                                 (ins GR32:$src1, i32i8imm:$src2),
3187                    "sbb{l}\t{$src2, $dst|$dst, $src2}",
3188                    [(set GR32:$dst, (sube GR32:$src1, i32immSExt8:$src2))]>;
3189 } // Uses = [EFLAGS]
3190 } // Defs = [EFLAGS]
3191
3192 let Defs = [EFLAGS] in {
3193 let isCommutable = 1 in {  // X = IMUL Y, Z --> X = IMUL Z, Y
3194 // Register-Register Signed Integer Multiply
3195 def IMUL16rr : I<0xAF, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src1,GR16:$src2),
3196                  "imul{w}\t{$src2, $dst|$dst, $src2}",
3197                  [(set GR16:$dst, EFLAGS,
3198                        (X86smul_flag GR16:$src1, GR16:$src2))]>, TB, OpSize;
3199 def IMUL32rr : I<0xAF, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src1,GR32:$src2),
3200                  "imul{l}\t{$src2, $dst|$dst, $src2}",
3201                  [(set GR32:$dst, EFLAGS,
3202                        (X86smul_flag GR32:$src1, GR32:$src2))]>, TB;
3203 }
3204
3205 // Register-Memory Signed Integer Multiply
3206 def IMUL16rm : I<0xAF, MRMSrcMem, (outs GR16:$dst),
3207                                   (ins GR16:$src1, i16mem:$src2),
3208                  "imul{w}\t{$src2, $dst|$dst, $src2}",
3209                  [(set GR16:$dst, EFLAGS,
3210                        (X86smul_flag GR16:$src1, (load addr:$src2)))]>,
3211                TB, OpSize;
3212 def IMUL32rm : I<0xAF, MRMSrcMem, (outs GR32:$dst), 
3213                  (ins GR32:$src1, i32mem:$src2),
3214                  "imul{l}\t{$src2, $dst|$dst, $src2}",
3215                  [(set GR32:$dst, EFLAGS,
3216                        (X86smul_flag GR32:$src1, (load addr:$src2)))]>, TB;
3217 } // Defs = [EFLAGS]
3218 } // end Two Address instructions
3219
3220 // Suprisingly enough, these are not two address instructions!
3221 let Defs = [EFLAGS] in {
3222 // Register-Integer Signed Integer Multiply
3223 def IMUL16rri  : Ii16<0x69, MRMSrcReg,                      // GR16 = GR16*I16
3224                       (outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
3225                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3226                       [(set GR16:$dst, EFLAGS, 
3227                             (X86smul_flag GR16:$src1, imm:$src2))]>, OpSize;
3228 def IMUL32rri  : Ii32<0x69, MRMSrcReg,                      // GR32 = GR32*I32
3229                       (outs GR32:$dst), (ins GR32:$src1, i32imm:$src2),
3230                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3231                       [(set GR32:$dst, EFLAGS,
3232                             (X86smul_flag GR32:$src1, imm:$src2))]>;
3233 def IMUL16rri8 : Ii8<0x6B, MRMSrcReg,                       // GR16 = GR16*I8
3234                      (outs GR16:$dst), (ins GR16:$src1, i16i8imm:$src2),
3235                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3236                      [(set GR16:$dst, EFLAGS,
3237                            (X86smul_flag GR16:$src1, i16immSExt8:$src2))]>,
3238                  OpSize;
3239 def IMUL32rri8 : Ii8<0x6B, MRMSrcReg,                       // GR32 = GR32*I8
3240                      (outs GR32:$dst), (ins GR32:$src1, i32i8imm:$src2),
3241                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3242                      [(set GR32:$dst, EFLAGS,
3243                            (X86smul_flag GR32:$src1, i32immSExt8:$src2))]>;
3244
3245 // Memory-Integer Signed Integer Multiply
3246 def IMUL16rmi  : Ii16<0x69, MRMSrcMem,                     // GR16 = [mem16]*I16
3247                       (outs GR16:$dst), (ins i16mem:$src1, i16imm:$src2),
3248                       "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3249                       [(set GR16:$dst, EFLAGS,
3250                             (X86smul_flag (load addr:$src1), imm:$src2))]>,
3251                  OpSize;
3252 def IMUL32rmi  : Ii32<0x69, MRMSrcMem,                     // GR32 = [mem32]*I32
3253                       (outs GR32:$dst), (ins i32mem:$src1, i32imm:$src2),
3254                       "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3255                       [(set GR32:$dst, EFLAGS,
3256                             (X86smul_flag (load addr:$src1), imm:$src2))]>;
3257 def IMUL16rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR16 = [mem16]*I8
3258                      (outs GR16:$dst), (ins i16mem:$src1, i16i8imm :$src2),
3259                      "imul{w}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3260                      [(set GR16:$dst, EFLAGS,
3261                            (X86smul_flag (load addr:$src1),
3262                                          i16immSExt8:$src2))]>, OpSize;
3263 def IMUL32rmi8 : Ii8<0x6B, MRMSrcMem,                       // GR32 = [mem32]*I8
3264                      (outs GR32:$dst), (ins i32mem:$src1, i32i8imm: $src2),
3265                      "imul{l}\t{$src2, $src1, $dst|$dst, $src1, $src2}",
3266                      [(set GR32:$dst, EFLAGS,
3267                            (X86smul_flag (load addr:$src1),
3268                                          i32immSExt8:$src2))]>;
3269 } // Defs = [EFLAGS]
3270
3271 //===----------------------------------------------------------------------===//
3272 // Test instructions are just like AND, except they don't generate a result.
3273 //
3274 let Defs = [EFLAGS] in {
3275 let isCommutable = 1 in {   // TEST X, Y   --> TEST Y, X
3276 def TEST8rr  : I<0x84, MRMSrcReg, (outs),  (ins GR8:$src1, GR8:$src2),
3277                      "test{b}\t{$src2, $src1|$src1, $src2}",
3278                      [(set EFLAGS, (X86cmp (and_su GR8:$src1, GR8:$src2), 0))]>;
3279 def TEST16rr : I<0x85, MRMSrcReg, (outs),  (ins GR16:$src1, GR16:$src2),
3280                      "test{w}\t{$src2, $src1|$src1, $src2}",
3281                      [(set EFLAGS, (X86cmp (and_su GR16:$src1, GR16:$src2),
3282                       0))]>,
3283                  OpSize;
3284 def TEST32rr : I<0x85, MRMSrcReg, (outs),  (ins GR32:$src1, GR32:$src2),
3285                      "test{l}\t{$src2, $src1|$src1, $src2}",
3286                      [(set EFLAGS, (X86cmp (and_su GR32:$src1, GR32:$src2),
3287                       0))]>;
3288 }
3289
3290 def TEST8i8  : Ii8<0xA8, RawFrm, (outs), (ins i8imm:$src),
3291                    "test{b}\t{$src, %al|%al, $src}", []>;
3292 def TEST16i16 : Ii16<0xA9, RawFrm, (outs), (ins i16imm:$src),
3293                      "test{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3294 def TEST32i32 : Ii32<0xA9, RawFrm, (outs), (ins i32imm:$src),
3295                      "test{l}\t{$src, %eax|%eax, $src}", []>;
3296
3297 def TEST8rm  : I<0x84, MRMSrcMem, (outs),  (ins GR8 :$src1, i8mem :$src2),
3298                      "test{b}\t{$src2, $src1|$src1, $src2}",
3299                      [(set EFLAGS, (X86cmp (and GR8:$src1, (loadi8 addr:$src2)),
3300                        0))]>;
3301 def TEST16rm : I<0x85, MRMSrcMem, (outs),  (ins GR16:$src1, i16mem:$src2),
3302                      "test{w}\t{$src2, $src1|$src1, $src2}",
3303                      [(set EFLAGS, (X86cmp (and GR16:$src1,
3304                                          (loadi16 addr:$src2)), 0))]>, OpSize;
3305 def TEST32rm : I<0x85, MRMSrcMem, (outs),  (ins GR32:$src1, i32mem:$src2),
3306                      "test{l}\t{$src2, $src1|$src1, $src2}",
3307                      [(set EFLAGS, (X86cmp (and GR32:$src1,
3308                                                 (loadi32 addr:$src2)), 0))]>;
3309
3310 def TEST8ri  : Ii8 <0xF6, MRM0r,                     // flags = GR8  & imm8
3311                     (outs),  (ins GR8:$src1, i8imm:$src2),
3312                     "test{b}\t{$src2, $src1|$src1, $src2}",
3313                     [(set EFLAGS, (X86cmp (and_su GR8:$src1, imm:$src2), 0))]>;
3314 def TEST16ri : Ii16<0xF7, MRM0r,                     // flags = GR16 & imm16
3315                     (outs),  (ins GR16:$src1, i16imm:$src2),
3316                     "test{w}\t{$src2, $src1|$src1, $src2}",
3317                     [(set EFLAGS, (X86cmp (and_su GR16:$src1, imm:$src2), 0))]>,
3318                     OpSize;
3319 def TEST32ri : Ii32<0xF7, MRM0r,                     // flags = GR32 & imm32
3320                     (outs),  (ins GR32:$src1, i32imm:$src2),
3321                     "test{l}\t{$src2, $src1|$src1, $src2}",
3322                     [(set EFLAGS, (X86cmp (and_su GR32:$src1, imm:$src2), 0))]>;
3323
3324 def TEST8mi  : Ii8 <0xF6, MRM0m,                   // flags = [mem8]  & imm8
3325                     (outs), (ins i8mem:$src1, i8imm:$src2),
3326                     "test{b}\t{$src2, $src1|$src1, $src2}",
3327                     [(set EFLAGS, (X86cmp (and (loadi8 addr:$src1), imm:$src2),
3328                      0))]>;
3329 def TEST16mi : Ii16<0xF7, MRM0m,                   // flags = [mem16] & imm16
3330                     (outs), (ins i16mem:$src1, i16imm:$src2),
3331                     "test{w}\t{$src2, $src1|$src1, $src2}",
3332                     [(set EFLAGS, (X86cmp (and (loadi16 addr:$src1), imm:$src2),
3333                      0))]>, OpSize;
3334 def TEST32mi : Ii32<0xF7, MRM0m,                   // flags = [mem32] & imm32
3335                     (outs), (ins i32mem:$src1, i32imm:$src2),
3336                     "test{l}\t{$src2, $src1|$src1, $src2}",
3337                     [(set EFLAGS, (X86cmp (and (loadi32 addr:$src1), imm:$src2),
3338                      0))]>;
3339 } // Defs = [EFLAGS]
3340
3341
3342 // Condition code ops, incl. set if equal/not equal/...
3343 let Defs = [EFLAGS], Uses = [AH], neverHasSideEffects = 1 in
3344 def SAHF     : I<0x9E, RawFrm, (outs),  (ins), "sahf", []>;  // flags = AH
3345 let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
3346 def LAHF     : I<0x9F, RawFrm, (outs),  (ins), "lahf", []>;  // AH = flags
3347
3348 let Uses = [EFLAGS] in {
3349 // Use sbb to materialize carry bit.
3350 let Defs = [EFLAGS], isCodeGenOnly = 1 in {
3351 // FIXME: These are pseudo ops that should be replaced with Pat<> patterns.
3352 // However, Pat<> can't replicate the destination reg into the inputs of the
3353 // result.
3354 // FIXME: Change these to have encoding Pseudo when X86MCCodeEmitter replaces
3355 // X86CodeEmitter.
3356 def SETB_C8r : I<0x18, MRMInitReg, (outs GR8:$dst), (ins), "",
3357                  [(set GR8:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
3358 def SETB_C16r : I<0x19, MRMInitReg, (outs GR16:$dst), (ins), "",
3359                  [(set GR16:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>,
3360                 OpSize;
3361 def SETB_C32r : I<0x19, MRMInitReg, (outs GR32:$dst), (ins), "",
3362                  [(set GR32:$dst, (X86setcc_c X86_COND_B, EFLAGS))]>;
3363 } // isCodeGenOnly
3364
3365 def SETEr    : I<0x94, MRM0r, 
3366                  (outs GR8   :$dst), (ins),
3367                  "sete\t$dst",
3368                  [(set GR8:$dst, (X86setcc X86_COND_E, EFLAGS))]>,
3369                TB;                        // GR8 = ==
3370 def SETEm    : I<0x94, MRM0m, 
3371                  (outs), (ins i8mem:$dst),
3372                  "sete\t$dst",
3373                  [(store (X86setcc X86_COND_E, EFLAGS), addr:$dst)]>,
3374                TB;                        // [mem8] = ==
3375
3376 def SETNEr   : I<0x95, MRM0r, 
3377                  (outs GR8   :$dst), (ins),
3378                  "setne\t$dst",
3379                  [(set GR8:$dst, (X86setcc X86_COND_NE, EFLAGS))]>,
3380                TB;                        // GR8 = !=
3381 def SETNEm   : I<0x95, MRM0m, 
3382                  (outs), (ins i8mem:$dst),
3383                  "setne\t$dst",
3384                  [(store (X86setcc X86_COND_NE, EFLAGS), addr:$dst)]>,
3385                TB;                        // [mem8] = !=
3386
3387 def SETLr    : I<0x9C, MRM0r, 
3388                  (outs GR8   :$dst), (ins),
3389                  "setl\t$dst",
3390                  [(set GR8:$dst, (X86setcc X86_COND_L, EFLAGS))]>,
3391                TB;                        // GR8 = <  signed
3392 def SETLm    : I<0x9C, MRM0m, 
3393                  (outs), (ins i8mem:$dst),
3394                  "setl\t$dst",
3395                  [(store (X86setcc X86_COND_L, EFLAGS), addr:$dst)]>,
3396                TB;                        // [mem8] = <  signed
3397
3398 def SETGEr   : I<0x9D, MRM0r, 
3399                  (outs GR8   :$dst), (ins),
3400                  "setge\t$dst",
3401                  [(set GR8:$dst, (X86setcc X86_COND_GE, EFLAGS))]>,
3402                TB;                        // GR8 = >= signed
3403 def SETGEm   : I<0x9D, MRM0m, 
3404                  (outs), (ins i8mem:$dst),
3405                  "setge\t$dst",
3406                  [(store (X86setcc X86_COND_GE, EFLAGS), addr:$dst)]>,
3407                TB;                        // [mem8] = >= signed
3408
3409 def SETLEr   : I<0x9E, MRM0r, 
3410                  (outs GR8   :$dst), (ins),
3411                  "setle\t$dst",
3412                  [(set GR8:$dst, (X86setcc X86_COND_LE, EFLAGS))]>,
3413                TB;                        // GR8 = <= signed
3414 def SETLEm   : I<0x9E, MRM0m, 
3415                  (outs), (ins i8mem:$dst),
3416                  "setle\t$dst",
3417                  [(store (X86setcc X86_COND_LE, EFLAGS), addr:$dst)]>,
3418                TB;                        // [mem8] = <= signed
3419
3420 def SETGr    : I<0x9F, MRM0r, 
3421                  (outs GR8   :$dst), (ins),
3422                  "setg\t$dst",
3423                  [(set GR8:$dst, (X86setcc X86_COND_G, EFLAGS))]>,
3424                TB;                        // GR8 = >  signed
3425 def SETGm    : I<0x9F, MRM0m, 
3426                  (outs), (ins i8mem:$dst),
3427                  "setg\t$dst",
3428                  [(store (X86setcc X86_COND_G, EFLAGS), addr:$dst)]>,
3429                TB;                        // [mem8] = >  signed
3430
3431 def SETBr    : I<0x92, MRM0r,
3432                  (outs GR8   :$dst), (ins),
3433                  "setb\t$dst",
3434                  [(set GR8:$dst, (X86setcc X86_COND_B, EFLAGS))]>,
3435                TB;                        // GR8 = <  unsign
3436 def SETBm    : I<0x92, MRM0m,
3437                  (outs), (ins i8mem:$dst),
3438                  "setb\t$dst",
3439                  [(store (X86setcc X86_COND_B, EFLAGS), addr:$dst)]>,
3440                TB;                        // [mem8] = <  unsign
3441
3442 def SETAEr   : I<0x93, MRM0r, 
3443                  (outs GR8   :$dst), (ins),
3444                  "setae\t$dst",
3445                  [(set GR8:$dst, (X86setcc X86_COND_AE, EFLAGS))]>,
3446                TB;                        // GR8 = >= unsign
3447 def SETAEm   : I<0x93, MRM0m, 
3448                  (outs), (ins i8mem:$dst),
3449                  "setae\t$dst",
3450                  [(store (X86setcc X86_COND_AE, EFLAGS), addr:$dst)]>,
3451                TB;                        // [mem8] = >= unsign
3452
3453 def SETBEr   : I<0x96, MRM0r, 
3454                  (outs GR8   :$dst), (ins),
3455                  "setbe\t$dst",
3456                  [(set GR8:$dst, (X86setcc X86_COND_BE, EFLAGS))]>,
3457                TB;                        // GR8 = <= unsign
3458 def SETBEm   : I<0x96, MRM0m, 
3459                  (outs), (ins i8mem:$dst),
3460                  "setbe\t$dst",
3461                  [(store (X86setcc X86_COND_BE, EFLAGS), addr:$dst)]>,
3462                TB;                        // [mem8] = <= unsign
3463
3464 def SETAr    : I<0x97, MRM0r, 
3465                  (outs GR8   :$dst), (ins),
3466                  "seta\t$dst",
3467                  [(set GR8:$dst, (X86setcc X86_COND_A, EFLAGS))]>,
3468                TB;                        // GR8 = >  signed
3469 def SETAm    : I<0x97, MRM0m, 
3470                  (outs), (ins i8mem:$dst),
3471                  "seta\t$dst",
3472                  [(store (X86setcc X86_COND_A, EFLAGS), addr:$dst)]>,
3473                TB;                        // [mem8] = >  signed
3474
3475 def SETSr    : I<0x98, MRM0r, 
3476                  (outs GR8   :$dst), (ins),
3477                  "sets\t$dst",
3478                  [(set GR8:$dst, (X86setcc X86_COND_S, EFLAGS))]>,
3479                TB;                        // GR8 = <sign bit>
3480 def SETSm    : I<0x98, MRM0m, 
3481                  (outs), (ins i8mem:$dst),
3482                  "sets\t$dst",
3483                  [(store (X86setcc X86_COND_S, EFLAGS), addr:$dst)]>,
3484                TB;                        // [mem8] = <sign bit>
3485 def SETNSr   : I<0x99, MRM0r, 
3486                  (outs GR8   :$dst), (ins),
3487                  "setns\t$dst",
3488                  [(set GR8:$dst, (X86setcc X86_COND_NS, EFLAGS))]>,
3489                TB;                        // GR8 = !<sign bit>
3490 def SETNSm   : I<0x99, MRM0m, 
3491                  (outs), (ins i8mem:$dst),
3492                  "setns\t$dst",
3493                  [(store (X86setcc X86_COND_NS, EFLAGS), addr:$dst)]>,
3494                TB;                        // [mem8] = !<sign bit>
3495
3496 def SETPr    : I<0x9A, MRM0r, 
3497                  (outs GR8   :$dst), (ins),
3498                  "setp\t$dst",
3499                  [(set GR8:$dst, (X86setcc X86_COND_P, EFLAGS))]>,
3500                TB;                        // GR8 = parity
3501 def SETPm    : I<0x9A, MRM0m, 
3502                  (outs), (ins i8mem:$dst),
3503                  "setp\t$dst",
3504                  [(store (X86setcc X86_COND_P, EFLAGS), addr:$dst)]>,
3505                TB;                        // [mem8] = parity
3506 def SETNPr   : I<0x9B, MRM0r, 
3507                  (outs GR8   :$dst), (ins),
3508                  "setnp\t$dst",
3509                  [(set GR8:$dst, (X86setcc X86_COND_NP, EFLAGS))]>,
3510                TB;                        // GR8 = not parity
3511 def SETNPm   : I<0x9B, MRM0m, 
3512                  (outs), (ins i8mem:$dst),
3513                  "setnp\t$dst",
3514                  [(store (X86setcc X86_COND_NP, EFLAGS), addr:$dst)]>,
3515                TB;                        // [mem8] = not parity
3516
3517 def SETOr    : I<0x90, MRM0r, 
3518                  (outs GR8   :$dst), (ins),
3519                  "seto\t$dst",
3520                  [(set GR8:$dst, (X86setcc X86_COND_O, EFLAGS))]>,
3521                TB;                        // GR8 = overflow
3522 def SETOm    : I<0x90, MRM0m, 
3523                  (outs), (ins i8mem:$dst),
3524                  "seto\t$dst",
3525                  [(store (X86setcc X86_COND_O, EFLAGS), addr:$dst)]>,
3526                TB;                        // [mem8] = overflow
3527 def SETNOr   : I<0x91, MRM0r, 
3528                  (outs GR8   :$dst), (ins),
3529                  "setno\t$dst",
3530                  [(set GR8:$dst, (X86setcc X86_COND_NO, EFLAGS))]>,
3531                TB;                        // GR8 = not overflow
3532 def SETNOm   : I<0x91, MRM0m, 
3533                  (outs), (ins i8mem:$dst),
3534                  "setno\t$dst",
3535                  [(store (X86setcc X86_COND_NO, EFLAGS), addr:$dst)]>,
3536                TB;                        // [mem8] = not overflow
3537 } // Uses = [EFLAGS]
3538
3539
3540 // Integer comparisons
3541 let Defs = [EFLAGS] in {
3542 def CMP8i8 : Ii8<0x3C, RawFrm, (outs), (ins i8imm:$src),
3543                  "cmp{b}\t{$src, %al|%al, $src}", []>;
3544 def CMP16i16 : Ii16<0x3D, RawFrm, (outs), (ins i16imm:$src),
3545                     "cmp{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3546 def CMP32i32 : Ii32<0x3D, RawFrm, (outs), (ins i32imm:$src),
3547                     "cmp{l}\t{$src, %eax|%eax, $src}", []>;
3548
3549 def CMP8rr  : I<0x38, MRMDestReg,
3550                 (outs), (ins GR8 :$src1, GR8 :$src2),
3551                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3552                 [(set EFLAGS, (X86cmp GR8:$src1, GR8:$src2))]>;
3553 def CMP16rr : I<0x39, MRMDestReg,
3554                 (outs), (ins GR16:$src1, GR16:$src2),
3555                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3556                 [(set EFLAGS, (X86cmp GR16:$src1, GR16:$src2))]>, OpSize;
3557 def CMP32rr : I<0x39, MRMDestReg,
3558                 (outs), (ins GR32:$src1, GR32:$src2),
3559                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3560                 [(set EFLAGS, (X86cmp GR32:$src1, GR32:$src2))]>;
3561 def CMP8mr  : I<0x38, MRMDestMem,
3562                 (outs), (ins i8mem :$src1, GR8 :$src2),
3563                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3564                 [(set EFLAGS, (X86cmp (loadi8 addr:$src1), GR8:$src2))]>;
3565 def CMP16mr : I<0x39, MRMDestMem,
3566                 (outs), (ins i16mem:$src1, GR16:$src2),
3567                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3568                 [(set EFLAGS, (X86cmp (loadi16 addr:$src1), GR16:$src2))]>,
3569                  OpSize;
3570 def CMP32mr : I<0x39, MRMDestMem,
3571                 (outs), (ins i32mem:$src1, GR32:$src2),
3572                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3573                 [(set EFLAGS, (X86cmp (loadi32 addr:$src1), GR32:$src2))]>;
3574 def CMP8rm  : I<0x3A, MRMSrcMem,
3575                 (outs), (ins GR8 :$src1, i8mem :$src2),
3576                 "cmp{b}\t{$src2, $src1|$src1, $src2}",
3577                 [(set EFLAGS, (X86cmp GR8:$src1, (loadi8 addr:$src2)))]>;
3578 def CMP16rm : I<0x3B, MRMSrcMem,
3579                 (outs), (ins GR16:$src1, i16mem:$src2),
3580                 "cmp{w}\t{$src2, $src1|$src1, $src2}",
3581                 [(set EFLAGS, (X86cmp GR16:$src1, (loadi16 addr:$src2)))]>,
3582                  OpSize;
3583 def CMP32rm : I<0x3B, MRMSrcMem,
3584                 (outs), (ins GR32:$src1, i32mem:$src2),
3585                 "cmp{l}\t{$src2, $src1|$src1, $src2}",
3586                 [(set EFLAGS, (X86cmp GR32:$src1, (loadi32 addr:$src2)))]>;
3587
3588 // These are alternate spellings for use by the disassembler, we mark them as
3589 // code gen only to ensure they aren't matched by the assembler.
3590 let isCodeGenOnly = 1 in {
3591   def CMP8rr_alt : I<0x3A, MRMSrcReg, (outs), (ins GR8:$src1, GR8:$src2),
3592                     "cmp{b}\t{$src2, $src1|$src1, $src2}", []>;
3593   def CMP16rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR16:$src1, GR16:$src2),
3594                      "cmp{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize;
3595   def CMP32rr_alt : I<0x3B, MRMSrcReg, (outs), (ins GR32:$src1, GR32:$src2),
3596                      "cmp{l}\t{$src2, $src1|$src1, $src2}", []>;
3597 }
3598
3599 def CMP8ri  : Ii8<0x80, MRM7r,
3600                   (outs), (ins GR8:$src1, i8imm:$src2),
3601                   "cmp{b}\t{$src2, $src1|$src1, $src2}",
3602                   [(set EFLAGS, (X86cmp GR8:$src1, imm:$src2))]>;
3603 def CMP16ri : Ii16<0x81, MRM7r,
3604                    (outs), (ins GR16:$src1, i16imm:$src2),
3605                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3606                    [(set EFLAGS, (X86cmp GR16:$src1, imm:$src2))]>, OpSize;
3607 def CMP32ri : Ii32<0x81, MRM7r,
3608                    (outs), (ins GR32:$src1, i32imm:$src2),
3609                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3610                    [(set EFLAGS, (X86cmp GR32:$src1, imm:$src2))]>;
3611 def CMP8mi  : Ii8 <0x80, MRM7m,
3612                    (outs), (ins i8mem :$src1, i8imm :$src2),
3613                    "cmp{b}\t{$src2, $src1|$src1, $src2}",
3614                    [(set EFLAGS, (X86cmp (loadi8 addr:$src1), imm:$src2))]>;
3615 def CMP16mi : Ii16<0x81, MRM7m,
3616                    (outs), (ins i16mem:$src1, i16imm:$src2),
3617                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3618                    [(set EFLAGS, (X86cmp (loadi16 addr:$src1), imm:$src2))]>,
3619                    OpSize;
3620 def CMP32mi : Ii32<0x81, MRM7m,
3621                    (outs), (ins i32mem:$src1, i32imm:$src2),
3622                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3623                    [(set EFLAGS, (X86cmp (loadi32 addr:$src1), imm:$src2))]>;
3624 def CMP16ri8 : Ii8<0x83, MRM7r,
3625                    (outs), (ins GR16:$src1, i16i8imm:$src2),
3626                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3627                    [(set EFLAGS, (X86cmp GR16:$src1, i16immSExt8:$src2))]>,
3628                     OpSize;
3629 def CMP16mi8 : Ii8<0x83, MRM7m,
3630                    (outs), (ins i16mem:$src1, i16i8imm:$src2),
3631                    "cmp{w}\t{$src2, $src1|$src1, $src2}",
3632                    [(set EFLAGS, (X86cmp (loadi16 addr:$src1),
3633                                          i16immSExt8:$src2))]>, OpSize;
3634 def CMP32mi8 : Ii8<0x83, MRM7m,
3635                    (outs), (ins i32mem:$src1, i32i8imm:$src2),
3636                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3637                    [(set EFLAGS, (X86cmp (loadi32 addr:$src1),
3638                                          i32immSExt8:$src2))]>;
3639 def CMP32ri8 : Ii8<0x83, MRM7r,
3640                    (outs), (ins GR32:$src1, i32i8imm:$src2),
3641                    "cmp{l}\t{$src2, $src1|$src1, $src2}",
3642                    [(set EFLAGS, (X86cmp GR32:$src1, i32immSExt8:$src2))]>;
3643 } // Defs = [EFLAGS]
3644
3645 // Bit tests.
3646 // TODO: BTC, BTR, and BTS
3647 let Defs = [EFLAGS] in {
3648 def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3649                "bt{w}\t{$src2, $src1|$src1, $src2}",
3650                [(set EFLAGS, (X86bt GR16:$src1, GR16:$src2))]>, OpSize, TB;
3651 def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3652                "bt{l}\t{$src2, $src1|$src1, $src2}",
3653                [(set EFLAGS, (X86bt GR32:$src1, GR32:$src2))]>, TB;
3654
3655 // Unlike with the register+register form, the memory+register form of the
3656 // bt instruction does not ignore the high bits of the index. From ISel's
3657 // perspective, this is pretty bizarre. Make these instructions disassembly
3658 // only for now.
3659
3660 def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3661                "bt{w}\t{$src2, $src1|$src1, $src2}", 
3662 //               [(X86bt (loadi16 addr:$src1), GR16:$src2),
3663 //                (implicit EFLAGS)]
3664                []
3665                >, OpSize, TB, Requires<[FastBTMem]>;
3666 def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3667                "bt{l}\t{$src2, $src1|$src1, $src2}", 
3668 //               [(X86bt (loadi32 addr:$src1), GR32:$src2),
3669 //                (implicit EFLAGS)]
3670                []
3671                >, TB, Requires<[FastBTMem]>;
3672
3673 def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3674                 "bt{w}\t{$src2, $src1|$src1, $src2}",
3675                 [(set EFLAGS, (X86bt GR16:$src1, i16immSExt8:$src2))]>,
3676                 OpSize, TB;
3677 def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3678                 "bt{l}\t{$src2, $src1|$src1, $src2}",
3679                 [(set EFLAGS, (X86bt GR32:$src1, i32immSExt8:$src2))]>, TB;
3680 // Note that these instructions don't need FastBTMem because that
3681 // only applies when the other operand is in a register. When it's
3682 // an immediate, bt is still fast.
3683 def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3684                 "bt{w}\t{$src2, $src1|$src1, $src2}",
3685                 [(set EFLAGS, (X86bt (loadi16 addr:$src1), i16immSExt8:$src2))
3686                  ]>, OpSize, TB;
3687 def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3688                 "bt{l}\t{$src2, $src1|$src1, $src2}",
3689                 [(set EFLAGS, (X86bt (loadi32 addr:$src1), i32immSExt8:$src2))
3690                  ]>, TB;
3691
3692 def BTC16rr : I<0xBB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3693                 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3694 def BTC32rr : I<0xBB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3695                 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3696 def BTC16mr : I<0xBB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3697                 "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3698 def BTC32mr : I<0xBB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3699                 "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3700 def BTC16ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3701                     "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3702 def BTC32ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3703                     "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3704 def BTC16mi8 : Ii8<0xBA, MRM7m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3705                     "btc{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3706 def BTC32mi8 : Ii8<0xBA, MRM7m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3707                     "btc{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3708
3709 def BTR16rr : I<0xB3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3710                 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3711 def BTR32rr : I<0xB3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3712                 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3713 def BTR16mr : I<0xB3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3714                 "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3715 def BTR32mr : I<0xB3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3716                 "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3717 def BTR16ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3718                     "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3719 def BTR32ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3720                     "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3721 def BTR16mi8 : Ii8<0xBA, MRM6m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3722                     "btr{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3723 def BTR32mi8 : Ii8<0xBA, MRM6m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3724                     "btr{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3725
3726 def BTS16rr : I<0xAB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
3727                 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3728 def BTS32rr : I<0xAB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
3729                 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3730 def BTS16mr : I<0xAB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
3731                 "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3732 def BTS32mr : I<0xAB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
3733                 "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3734 def BTS16ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR16:$src1, i16i8imm:$src2),
3735                     "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3736 def BTS32ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR32:$src1, i32i8imm:$src2),
3737                     "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3738 def BTS16mi8 : Ii8<0xBA, MRM5m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
3739                     "bts{w}\t{$src2, $src1|$src1, $src2}", []>, OpSize, TB;
3740 def BTS32mi8 : Ii8<0xBA, MRM5m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
3741                     "bts{l}\t{$src2, $src1|$src1, $src2}", []>, TB;
3742 } // Defs = [EFLAGS]
3743
3744 // Sign/Zero extenders
3745 // Use movsbl intead of movsbw; we don't care about the high 16 bits
3746 // of the register here. This has a smaller encoding and avoids a
3747 // partial-register update.  Actual movsbw included for the disassembler.
3748 def MOVSX16rr8W : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
3749                     "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3750 def MOVSX16rm8W : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
3751                     "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3752 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
3753                    "", [(set GR16:$dst, (sext GR8:$src))]>, TB;
3754 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
3755                    "", [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB;
3756 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
3757                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
3758                    [(set GR32:$dst, (sext GR8:$src))]>, TB;
3759 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
3760                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
3761                    [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
3762 def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
3763                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
3764                    [(set GR32:$dst, (sext GR16:$src))]>, TB;
3765 def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
3766                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
3767                    [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
3768
3769 // Use movzbl intead of movzbw; we don't care about the high 16 bits
3770 // of the register here. This has a smaller encoding and avoids a
3771 // partial-register update.  Actual movzbw included for the disassembler.
3772 def MOVZX16rr8W : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
3773                     "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3774 def MOVZX16rm8W : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
3775                     "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;  
3776 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
3777                    "", [(set GR16:$dst, (zext GR8:$src))]>, TB;
3778 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
3779                    "", [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB;
3780 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
3781                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
3782                    [(set GR32:$dst, (zext GR8:$src))]>, TB;
3783 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
3784                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
3785                    [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
3786 def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
3787                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
3788                    [(set GR32:$dst, (zext GR16:$src))]>, TB;
3789 def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
3790                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
3791                    [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
3792
3793 // These are the same as the regular MOVZX32rr8 and MOVZX32rm8
3794 // except that they use GR32_NOREX for the output operand register class
3795 // instead of GR32. This allows them to operate on h registers on x86-64.
3796 def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
3797                          (outs GR32_NOREX:$dst), (ins GR8:$src),
3798                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
3799                          []>, TB;
3800 let mayLoad = 1 in
3801 def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
3802                          (outs GR32_NOREX:$dst), (ins i8mem:$src),
3803                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
3804                          []>, TB;
3805
3806 let neverHasSideEffects = 1 in {
3807   let Defs = [AX], Uses = [AL] in
3808   def CBW : I<0x98, RawFrm, (outs), (ins),
3809               "{cbtw|cbw}", []>, OpSize;   // AX = signext(AL)
3810   let Defs = [EAX], Uses = [AX] in
3811   def CWDE : I<0x98, RawFrm, (outs), (ins),
3812               "{cwtl|cwde}", []>;   // EAX = signext(AX)
3813
3814   let Defs = [AX,DX], Uses = [AX] in
3815   def CWD : I<0x99, RawFrm, (outs), (ins),
3816               "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
3817   let Defs = [EAX,EDX], Uses = [EAX] in
3818   def CDQ : I<0x99, RawFrm, (outs), (ins),
3819               "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
3820 }
3821
3822 //===----------------------------------------------------------------------===//
3823 // Alias Instructions
3824 //===----------------------------------------------------------------------===//
3825
3826 // Alias instructions that map movr0 to xor.
3827 // FIXME: remove when we can teach regalloc that xor reg, reg is ok.
3828 // FIXME: Set encoding to pseudo.
3829 let Defs = [EFLAGS], isReMaterializable = 1, isAsCheapAsAMove = 1,
3830     isCodeGenOnly = 1 in {
3831 def MOV8r0   : I<0x30, MRMInitReg, (outs GR8 :$dst), (ins), "",
3832                  [(set GR8:$dst, 0)]>;
3833
3834 // We want to rewrite MOV16r0 in terms of MOV32r0, because it's a smaller
3835 // encoding and avoids a partial-register update sometimes, but doing so
3836 // at isel time interferes with rematerialization in the current register
3837 // allocator. For now, this is rewritten when the instruction is lowered
3838 // to an MCInst.
3839 def MOV16r0   : I<0x31, MRMInitReg, (outs GR16:$dst), (ins),
3840                  "",
3841                  [(set GR16:$dst, 0)]>, OpSize;
3842                  
3843 // FIXME: Set encoding to pseudo.
3844 def MOV32r0  : I<0x31, MRMInitReg, (outs GR32:$dst), (ins), "",
3845                  [(set GR32:$dst, 0)]>;
3846 }
3847
3848 //===----------------------------------------------------------------------===//
3849 // Thread Local Storage Instructions
3850 //
3851
3852 // ELF TLS Support
3853 // All calls clobber the non-callee saved registers. ESP is marked as
3854 // a use to prevent stack-pointer assignments that appear immediately
3855 // before calls from potentially appearing dead.
3856 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
3857             MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
3858             XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
3859             XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
3860     Uses = [ESP] in
3861 def TLS_addr32 : I<0, Pseudo, (outs), (ins i32mem:$sym),
3862                   "leal\t$sym, %eax; "
3863                   "call\t___tls_get_addr@PLT",
3864                   [(X86tlsaddr tls32addr:$sym)]>,
3865                   Requires<[In32BitMode]>;
3866
3867 // Darwin TLS Support
3868 // For i386, the address of the thunk is passed on the stack, on return the 
3869 // address of the variable is in %eax.  %ecx is trashed during the function 
3870 // call.  All other registers are preserved.
3871 let Defs = [EAX, ECX],
3872     Uses = [ESP],
3873     usesCustomInserter = 1 in
3874 def TLSCall_32 : I<0, Pseudo, (outs), (ins i32mem:$sym),
3875                 "# TLSCall_32",
3876                 [(X86TLSCall addr:$sym)]>,
3877                 Requires<[In32BitMode]>;
3878                 
3879 let AddedComplexity = 5, isCodeGenOnly = 1 in
3880 def GS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
3881                    "movl\t%gs:$src, $dst",
3882                    [(set GR32:$dst, (gsload addr:$src))]>, SegGS;
3883
3884 let AddedComplexity = 5, isCodeGenOnly = 1 in
3885 def FS_MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
3886                    "movl\t%fs:$src, $dst",
3887                    [(set GR32:$dst, (fsload addr:$src))]>, SegFS;
3888
3889 //===----------------------------------------------------------------------===//
3890 // EH Pseudo Instructions
3891 //
3892 let isTerminator = 1, isReturn = 1, isBarrier = 1,
3893     hasCtrlDep = 1, isCodeGenOnly = 1 in {
3894 def EH_RETURN   : I<0xC3, RawFrm, (outs), (ins GR32:$addr),
3895                     "ret\t#eh_return, addr: $addr",
3896                     [(X86ehret GR32:$addr)]>;
3897
3898 }
3899
3900 //===----------------------------------------------------------------------===//
3901 // Atomic support
3902 //
3903
3904 // Atomic swap. These are just normal xchg instructions. But since a memory
3905 // operand is referenced, the atomicity is ensured.
3906 let Constraints = "$val = $dst" in {
3907 def XCHG32rm : I<0x87, MRMSrcMem, (outs GR32:$dst), 
3908                  (ins GR32:$val, i32mem:$ptr),
3909                "xchg{l}\t{$val, $ptr|$ptr, $val}", 
3910                [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))]>;
3911 def XCHG16rm : I<0x87, MRMSrcMem, (outs GR16:$dst), 
3912                  (ins GR16:$val, i16mem:$ptr),
3913                "xchg{w}\t{$val, $ptr|$ptr, $val}", 
3914                [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))]>, 
3915                 OpSize;
3916 def XCHG8rm  : I<0x86, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
3917                "xchg{b}\t{$val, $ptr|$ptr, $val}", 
3918                [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))]>;
3919
3920 def XCHG32rr : I<0x87, MRMSrcReg, (outs GR32:$dst), (ins GR32:$val, GR32:$src),
3921                  "xchg{l}\t{$val, $src|$src, $val}", []>;
3922 def XCHG16rr : I<0x87, MRMSrcReg, (outs GR16:$dst), (ins GR16:$val, GR16:$src),
3923                  "xchg{w}\t{$val, $src|$src, $val}", []>, OpSize;
3924 def XCHG8rr : I<0x86, MRMSrcReg, (outs GR8:$dst), (ins GR8:$val, GR8:$src),
3925                 "xchg{b}\t{$val, $src|$src, $val}", []>;
3926 }
3927
3928 def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src),
3929                   "xchg{w}\t{$src, %ax|%ax, $src}", []>, OpSize;
3930 def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src),
3931                   "xchg{l}\t{$src, %eax|%eax, $src}", []>;
3932
3933 // Atomic compare and swap.
3934 let Defs = [EAX, EFLAGS], Uses = [EAX] in {
3935 def LCMPXCHG32 : I<0xB1, MRMDestMem, (outs), (ins i32mem:$ptr, GR32:$swap),
3936                "lock\n\t"
3937                "cmpxchg{l}\t{$swap, $ptr|$ptr, $swap}",
3938                [(X86cas addr:$ptr, GR32:$swap, 4)]>, TB, LOCK;
3939 }
3940 let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in {
3941 def LCMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$ptr),
3942                "lock\n\t"
3943                "cmpxchg8b\t$ptr",
3944                [(X86cas8 addr:$ptr)]>, TB, LOCK;
3945 }
3946
3947 let Defs = [AX, EFLAGS], Uses = [AX] in {
3948 def LCMPXCHG16 : I<0xB1, MRMDestMem, (outs), (ins i16mem:$ptr, GR16:$swap),
3949                "lock\n\t"
3950                "cmpxchg{w}\t{$swap, $ptr|$ptr, $swap}",
3951                [(X86cas addr:$ptr, GR16:$swap, 2)]>, TB, OpSize, LOCK;
3952 }
3953 let Defs = [AL, EFLAGS], Uses = [AL] in {
3954 def LCMPXCHG8 : I<0xB0, MRMDestMem, (outs), (ins i8mem:$ptr, GR8:$swap),
3955                "lock\n\t"
3956                "cmpxchg{b}\t{$swap, $ptr|$ptr, $swap}",
3957                [(X86cas addr:$ptr, GR8:$swap, 1)]>, TB, LOCK;
3958 }
3959
3960 // Atomic exchange and add
3961 let Constraints = "$val = $dst", Defs = [EFLAGS] in {
3962 def LXADD32 : I<0xC1, MRMSrcMem, (outs GR32:$dst), (ins GR32:$val, i32mem:$ptr),
3963                "lock\n\t"
3964                "xadd{l}\t{$val, $ptr|$ptr, $val}",
3965                [(set GR32:$dst, (atomic_load_add_32 addr:$ptr, GR32:$val))]>,
3966                 TB, LOCK;
3967 def LXADD16 : I<0xC1, MRMSrcMem, (outs GR16:$dst), (ins GR16:$val, i16mem:$ptr),
3968                "lock\n\t"
3969                "xadd{w}\t{$val, $ptr|$ptr, $val}",
3970                [(set GR16:$dst, (atomic_load_add_16 addr:$ptr, GR16:$val))]>,
3971                 TB, OpSize, LOCK;
3972 def LXADD8  : I<0xC0, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
3973                "lock\n\t"
3974                "xadd{b}\t{$val, $ptr|$ptr, $val}",
3975                [(set GR8:$dst, (atomic_load_add_8 addr:$ptr, GR8:$val))]>,
3976                 TB, LOCK;
3977 }
3978
3979 def XADD8rr : I<0xC0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
3980                 "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
3981 def XADD16rr : I<0xC1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
3982                  "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3983 def XADD32rr  : I<0xC1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
3984                  "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
3985
3986 let mayLoad = 1, mayStore = 1 in {
3987 def XADD8rm   : I<0xC0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
3988                  "xadd{b}\t{$src, $dst|$dst, $src}", []>, TB;
3989 def XADD16rm  : I<0xC1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
3990                  "xadd{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3991 def XADD32rm  : I<0xC1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
3992                  "xadd{l}\t{$src, $dst|$dst, $src}", []>, TB;
3993 }
3994
3995 def CMPXCHG8rr : I<0xB0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
3996                    "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
3997 def CMPXCHG16rr : I<0xB1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
3998                     "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
3999 def CMPXCHG32rr  : I<0xB1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
4000                      "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
4001
4002 let mayLoad = 1, mayStore = 1 in {
4003 def CMPXCHG8rm   : I<0xB0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
4004                      "cmpxchg{b}\t{$src, $dst|$dst, $src}", []>, TB;
4005 def CMPXCHG16rm  : I<0xB1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
4006                      "cmpxchg{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4007 def CMPXCHG32rm  : I<0xB1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
4008                      "cmpxchg{l}\t{$src, $dst|$dst, $src}", []>, TB;
4009 }
4010
4011 let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in
4012 def CMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$dst),
4013                   "cmpxchg8b\t$dst", []>, TB;
4014
4015 // Optimized codegen when the non-memory output is not used.
4016 // FIXME: Use normal add / sub instructions and add lock prefix dynamically.
4017 let Defs = [EFLAGS], mayLoad = 1, mayStore = 1 in {
4018 def LOCK_ADD8mr  : I<0x00, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src2),
4019                     "lock\n\t"
4020                     "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4021 def LOCK_ADD16mr  : I<0x01, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
4022                     "lock\n\t"
4023                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4024 def LOCK_ADD32mr  : I<0x01, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2),
4025                     "lock\n\t"
4026                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4027 def LOCK_ADD8mi   : Ii8<0x80, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src2),
4028                     "lock\n\t"
4029                     "add{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4030 def LOCK_ADD16mi  : Ii16<0x81, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src2),
4031                     "lock\n\t"
4032                      "add{w}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4033 def LOCK_ADD32mi  : Ii32<0x81, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src2),
4034                     "lock\n\t"
4035                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4036 def LOCK_ADD16mi8 : Ii8<0x83, MRM0m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
4037                     "lock\n\t"
4038                     "add{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4039 def LOCK_ADD32mi8 : Ii8<0x83, MRM0m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
4040                     "lock\n\t"
4041                     "add{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4042
4043 def LOCK_INC8m  : I<0xFE, MRM0m, (outs), (ins i8mem :$dst),
4044                     "lock\n\t"
4045                     "inc{b}\t$dst", []>, LOCK;
4046 def LOCK_INC16m : I<0xFF, MRM0m, (outs), (ins i16mem:$dst),
4047                     "lock\n\t"
4048                     "inc{w}\t$dst", []>, OpSize, LOCK;
4049 def LOCK_INC32m : I<0xFF, MRM0m, (outs), (ins i32mem:$dst),
4050                     "lock\n\t"
4051                     "inc{l}\t$dst", []>, LOCK;
4052
4053 def LOCK_SUB8mr   : I<0x28, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src2),
4054                     "lock\n\t"
4055                     "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4056 def LOCK_SUB16mr  : I<0x29, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src2),
4057                     "lock\n\t"
4058                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4059 def LOCK_SUB32mr  : I<0x29, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src2), 
4060                     "lock\n\t"
4061                     "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4062 def LOCK_SUB8mi   : Ii8<0x80, MRM5m, (outs), (ins i8mem :$dst, i8imm:$src2), 
4063                     "lock\n\t"
4064                     "sub{b}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4065 def LOCK_SUB16mi  : Ii16<0x81, MRM5m, (outs), (ins i16mem:$dst, i16imm:$src2), 
4066                     "lock\n\t"
4067                     "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4068 def LOCK_SUB32mi  : Ii32<0x81, MRM5m, (outs), (ins i32mem:$dst, i32imm:$src2), 
4069                     "lock\n\t"
4070                      "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4071 def LOCK_SUB16mi8 : Ii8<0x83, MRM5m, (outs), (ins i16mem:$dst, i16i8imm :$src2),
4072                     "lock\n\t"
4073                      "sub{w}\t{$src2, $dst|$dst, $src2}", []>, OpSize, LOCK;
4074 def LOCK_SUB32mi8 : Ii8<0x83, MRM5m, (outs), (ins i32mem:$dst, i32i8imm :$src2),
4075                     "lock\n\t"
4076                      "sub{l}\t{$src2, $dst|$dst, $src2}", []>, LOCK;
4077
4078 def LOCK_DEC8m  : I<0xFE, MRM1m, (outs), (ins i8mem :$dst),
4079                     "lock\n\t"
4080                     "dec{b}\t$dst", []>, LOCK;
4081 def LOCK_DEC16m : I<0xFF, MRM1m, (outs), (ins i16mem:$dst),
4082                     "lock\n\t"
4083                     "dec{w}\t$dst", []>, OpSize, LOCK;
4084 def LOCK_DEC32m : I<0xFF, MRM1m, (outs), (ins i32mem:$dst),
4085                     "lock\n\t"
4086                     "dec{l}\t$dst", []>, LOCK;
4087 }
4088
4089 // Atomic exchange, and, or, xor
4090 let Constraints = "$val = $dst", Defs = [EFLAGS],
4091                   usesCustomInserter = 1 in {
4092 def ATOMAND32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4093                "#ATOMAND32 PSEUDO!", 
4094                [(set GR32:$dst, (atomic_load_and_32 addr:$ptr, GR32:$val))]>;
4095 def ATOMOR32 : I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4096                "#ATOMOR32 PSEUDO!", 
4097                [(set GR32:$dst, (atomic_load_or_32 addr:$ptr, GR32:$val))]>;
4098 def ATOMXOR32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4099                "#ATOMXOR32 PSEUDO!", 
4100                [(set GR32:$dst, (atomic_load_xor_32 addr:$ptr, GR32:$val))]>;
4101 def ATOMNAND32 : I<0, Pseudo,(outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4102                "#ATOMNAND32 PSEUDO!", 
4103                [(set GR32:$dst, (atomic_load_nand_32 addr:$ptr, GR32:$val))]>;
4104 def ATOMMIN32: I<0, Pseudo, (outs GR32:$dst), (ins i32mem:$ptr, GR32:$val),
4105                "#ATOMMIN32 PSEUDO!", 
4106                [(set GR32:$dst, (atomic_load_min_32 addr:$ptr, GR32:$val))]>;
4107 def ATOMMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4108                "#ATOMMAX32 PSEUDO!", 
4109                [(set GR32:$dst, (atomic_load_max_32 addr:$ptr, GR32:$val))]>;
4110 def ATOMUMIN32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4111                "#ATOMUMIN32 PSEUDO!", 
4112                [(set GR32:$dst, (atomic_load_umin_32 addr:$ptr, GR32:$val))]>;
4113 def ATOMUMAX32: I<0, Pseudo, (outs GR32:$dst),(ins i32mem:$ptr, GR32:$val),
4114                "#ATOMUMAX32 PSEUDO!", 
4115                [(set GR32:$dst, (atomic_load_umax_32 addr:$ptr, GR32:$val))]>;
4116
4117 def ATOMAND16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4118                "#ATOMAND16 PSEUDO!", 
4119                [(set GR16:$dst, (atomic_load_and_16 addr:$ptr, GR16:$val))]>;
4120 def ATOMOR16 : I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4121                "#ATOMOR16 PSEUDO!", 
4122                [(set GR16:$dst, (atomic_load_or_16 addr:$ptr, GR16:$val))]>;
4123 def ATOMXOR16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4124                "#ATOMXOR16 PSEUDO!", 
4125                [(set GR16:$dst, (atomic_load_xor_16 addr:$ptr, GR16:$val))]>;
4126 def ATOMNAND16 : I<0, Pseudo,(outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4127                "#ATOMNAND16 PSEUDO!", 
4128                [(set GR16:$dst, (atomic_load_nand_16 addr:$ptr, GR16:$val))]>;
4129 def ATOMMIN16: I<0, Pseudo, (outs GR16:$dst), (ins i16mem:$ptr, GR16:$val),
4130                "#ATOMMIN16 PSEUDO!", 
4131                [(set GR16:$dst, (atomic_load_min_16 addr:$ptr, GR16:$val))]>;
4132 def ATOMMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4133                "#ATOMMAX16 PSEUDO!", 
4134                [(set GR16:$dst, (atomic_load_max_16 addr:$ptr, GR16:$val))]>;
4135 def ATOMUMIN16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4136                "#ATOMUMIN16 PSEUDO!", 
4137                [(set GR16:$dst, (atomic_load_umin_16 addr:$ptr, GR16:$val))]>;
4138 def ATOMUMAX16: I<0, Pseudo, (outs GR16:$dst),(ins i16mem:$ptr, GR16:$val),
4139                "#ATOMUMAX16 PSEUDO!", 
4140                [(set GR16:$dst, (atomic_load_umax_16 addr:$ptr, GR16:$val))]>;
4141
4142 def ATOMAND8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
4143                "#ATOMAND8 PSEUDO!", 
4144                [(set GR8:$dst, (atomic_load_and_8 addr:$ptr, GR8:$val))]>;
4145 def ATOMOR8 : I<0, Pseudo, (outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
4146                "#ATOMOR8 PSEUDO!", 
4147                [(set GR8:$dst, (atomic_load_or_8 addr:$ptr, GR8:$val))]>;
4148 def ATOMXOR8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
4149                "#ATOMXOR8 PSEUDO!", 
4150                [(set GR8:$dst, (atomic_load_xor_8 addr:$ptr, GR8:$val))]>;
4151 def ATOMNAND8 : I<0, Pseudo,(outs GR8:$dst),(ins i8mem:$ptr, GR8:$val),
4152                "#ATOMNAND8 PSEUDO!", 
4153                [(set GR8:$dst, (atomic_load_nand_8 addr:$ptr, GR8:$val))]>;
4154 }
4155
4156 let Constraints = "$val1 = $dst1, $val2 = $dst2", 
4157                   Defs = [EFLAGS, EAX, EBX, ECX, EDX],
4158                   Uses = [EAX, EBX, ECX, EDX],
4159                   mayLoad = 1, mayStore = 1,
4160                   usesCustomInserter = 1 in {
4161 def ATOMAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4162                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4163                "#ATOMAND6432 PSEUDO!", []>;
4164 def ATOMOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4165                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4166                "#ATOMOR6432 PSEUDO!", []>;
4167 def ATOMXOR6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4168                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4169                "#ATOMXOR6432 PSEUDO!", []>;
4170 def ATOMNAND6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4171                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4172                "#ATOMNAND6432 PSEUDO!", []>;
4173 def ATOMADD6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4174                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4175                "#ATOMADD6432 PSEUDO!", []>;
4176 def ATOMSUB6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4177                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4178                "#ATOMSUB6432 PSEUDO!", []>;
4179 def ATOMSWAP6432 : I<0, Pseudo, (outs GR32:$dst1, GR32:$dst2),
4180                                (ins i64mem:$ptr, GR32:$val1, GR32:$val2),
4181                "#ATOMSWAP6432 PSEUDO!", []>;
4182 }
4183
4184 // Segmentation support instructions.
4185
4186 def LAR16rm : I<0x02, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src), 
4187                 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4188 def LAR16rr : I<0x02, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
4189                 "lar{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4190
4191 // i16mem operand in LAR32rm and GR32 operand in LAR32rr is not a typo.
4192 def LAR32rm : I<0x02, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src), 
4193                 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB;
4194 def LAR32rr : I<0x02, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4195                 "lar{l}\t{$src, $dst|$dst, $src}", []>, TB;
4196
4197 def LSL16rm : I<0x03, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
4198                 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize; 
4199 def LSL16rr : I<0x03, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
4200                 "lsl{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4201 def LSL32rm : I<0x03, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
4202                 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB; 
4203 def LSL32rr : I<0x03, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4204                 "lsl{l}\t{$src, $dst|$dst, $src}", []>, TB;
4205                 
4206 def INVLPG : I<0x01, MRM7m, (outs), (ins i8mem:$addr), "invlpg\t$addr", []>, TB;
4207
4208 def STRr : I<0x00, MRM1r, (outs GR16:$dst), (ins),
4209              "str{w}\t{$dst}", []>, TB;
4210 def STRm : I<0x00, MRM1m, (outs i16mem:$dst), (ins),
4211              "str{w}\t{$dst}", []>, TB;
4212 def LTRr : I<0x00, MRM3r, (outs), (ins GR16:$src),
4213              "ltr{w}\t{$src}", []>, TB;
4214 def LTRm : I<0x00, MRM3m, (outs), (ins i16mem:$src),
4215              "ltr{w}\t{$src}", []>, TB;
4216              
4217 def PUSHFS16 : I<0xa0, RawFrm, (outs), (ins),
4218                  "push{w}\t%fs", []>, OpSize, TB;
4219 def PUSHFS32 : I<0xa0, RawFrm, (outs), (ins),
4220                  "push{l}\t%fs", []>, TB;
4221 def PUSHGS16 : I<0xa8, RawFrm, (outs), (ins),
4222                  "push{w}\t%gs", []>, OpSize, TB;
4223 def PUSHGS32 : I<0xa8, RawFrm, (outs), (ins),
4224                  "push{l}\t%gs", []>, TB;
4225
4226 def POPFS16 : I<0xa1, RawFrm, (outs), (ins),
4227                 "pop{w}\t%fs", []>, OpSize, TB;
4228 def POPFS32 : I<0xa1, RawFrm, (outs), (ins),
4229                 "pop{l}\t%fs", []>, TB;
4230 def POPGS16 : I<0xa9, RawFrm, (outs), (ins),
4231                 "pop{w}\t%gs", []>, OpSize, TB;
4232 def POPGS32 : I<0xa9, RawFrm, (outs), (ins),
4233                 "pop{l}\t%gs", []>, TB;
4234
4235 def LDS16rm : I<0xc5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4236                 "lds{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
4237 def LDS32rm : I<0xc5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4238                 "lds{l}\t{$src, $dst|$dst, $src}", []>;
4239 def LSS16rm : I<0xb2, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4240                 "lss{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4241 def LSS32rm : I<0xb2, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4242                 "lss{l}\t{$src, $dst|$dst, $src}", []>, TB;
4243 def LES16rm : I<0xc4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4244                 "les{w}\t{$src, $dst|$dst, $src}", []>, OpSize;
4245 def LES32rm : I<0xc4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4246                 "les{l}\t{$src, $dst|$dst, $src}", []>;
4247 def LFS16rm : I<0xb4, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4248                 "lfs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4249 def LFS32rm : I<0xb4, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4250                 "lfs{l}\t{$src, $dst|$dst, $src}", []>, TB;
4251 def LGS16rm : I<0xb5, MRMSrcMem, (outs GR16:$dst), (ins opaque32mem:$src),
4252                 "lgs{w}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
4253 def LGS32rm : I<0xb5, MRMSrcMem, (outs GR32:$dst), (ins opaque48mem:$src),
4254                 "lgs{l}\t{$src, $dst|$dst, $src}", []>, TB;
4255
4256 def VERRr : I<0x00, MRM4r, (outs), (ins GR16:$seg),
4257               "verr\t$seg", []>, TB;
4258 def VERRm : I<0x00, MRM4m, (outs), (ins i16mem:$seg),
4259               "verr\t$seg", []>, TB;
4260 def VERWr : I<0x00, MRM5r, (outs), (ins GR16:$seg),
4261               "verw\t$seg", []>, TB;
4262 def VERWm : I<0x00, MRM5m, (outs), (ins i16mem:$seg),
4263               "verw\t$seg", []>, TB;
4264
4265 // Descriptor-table support instructions
4266
4267 def SGDTm : I<0x01, MRM0m, (outs opaque48mem:$dst), (ins),
4268               "sgdt\t$dst", []>, TB;
4269 def SIDTm : I<0x01, MRM1m, (outs opaque48mem:$dst), (ins),
4270               "sidt\t$dst", []>, TB;
4271 def SLDT16r : I<0x00, MRM0r, (outs GR16:$dst), (ins),
4272                 "sldt{w}\t$dst", []>, TB;
4273 def SLDT16m : I<0x00, MRM0m, (outs i16mem:$dst), (ins),
4274                 "sldt{w}\t$dst", []>, TB;
4275 def LGDTm : I<0x01, MRM2m, (outs), (ins opaque48mem:$src),
4276               "lgdt\t$src", []>, TB;
4277 def LIDTm : I<0x01, MRM3m, (outs), (ins opaque48mem:$src),
4278               "lidt\t$src", []>, TB;
4279 def LLDT16r : I<0x00, MRM2r, (outs), (ins GR16:$src),
4280                 "lldt{w}\t$src", []>, TB;
4281 def LLDT16m : I<0x00, MRM2m, (outs), (ins i16mem:$src),
4282                 "lldt{w}\t$src", []>, TB;
4283                 
4284 // Lock instruction prefix
4285 def LOCK_PREFIX : I<0xF0, RawFrm, (outs),  (ins), "lock", []>;
4286
4287 // Repeat string operation instruction prefixes
4288 // These uses the DF flag in the EFLAGS register to inc or dec ECX
4289 let Defs = [ECX], Uses = [ECX,EFLAGS] in {
4290 // Repeat (used with INS, OUTS, MOVS, LODS and STOS)
4291 def REP_PREFIX : I<0xF3, RawFrm, (outs),  (ins), "rep", []>;
4292 // Repeat while not equal (used with CMPS and SCAS)
4293 def REPNE_PREFIX : I<0xF2, RawFrm, (outs),  (ins), "repne", []>;
4294 }
4295
4296 // Segment override instruction prefixes
4297 def CS_PREFIX : I<0x2E, RawFrm, (outs),  (ins), "cs", []>;
4298 def SS_PREFIX : I<0x36, RawFrm, (outs),  (ins), "ss", []>;
4299 def DS_PREFIX : I<0x3E, RawFrm, (outs),  (ins), "ds", []>;
4300 def ES_PREFIX : I<0x26, RawFrm, (outs),  (ins), "es", []>;
4301 def FS_PREFIX : I<0x64, RawFrm, (outs),  (ins), "fs", []>;
4302 def GS_PREFIX : I<0x65, RawFrm, (outs),  (ins), "gs", []>;
4303
4304 // String manipulation instructions
4305
4306 def LODSB : I<0xAC, RawFrm, (outs), (ins), "lodsb", []>;
4307 def LODSW : I<0xAD, RawFrm, (outs), (ins), "lodsw", []>, OpSize;
4308 def LODSD : I<0xAD, RawFrm, (outs), (ins), "lods{l|d}", []>;
4309
4310 def OUTSB : I<0x6E, RawFrm, (outs), (ins), "outsb", []>;
4311 def OUTSW : I<0x6F, RawFrm, (outs), (ins), "outsw", []>, OpSize;
4312 def OUTSD : I<0x6F, RawFrm, (outs), (ins), "outs{l|d}", []>;
4313
4314 // CPU flow control instructions
4315
4316 def HLT : I<0xF4, RawFrm, (outs), (ins), "hlt", []>;
4317 def RSM : I<0xAA, RawFrm, (outs), (ins), "rsm", []>, TB;
4318
4319 // FPU control instructions
4320
4321 def FNINIT : I<0xE3, RawFrm, (outs), (ins), "fninit", []>, DB;
4322
4323 // Flag instructions
4324
4325 def CLC : I<0xF8, RawFrm, (outs), (ins), "clc", []>;
4326 def STC : I<0xF9, RawFrm, (outs), (ins), "stc", []>;
4327 def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", []>;
4328 def STI : I<0xFB, RawFrm, (outs), (ins), "sti", []>;
4329 def CLD : I<0xFC, RawFrm, (outs), (ins), "cld", []>;
4330 def STD : I<0xFD, RawFrm, (outs), (ins), "std", []>;
4331 def CMC : I<0xF5, RawFrm, (outs), (ins), "cmc", []>;
4332
4333 def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", []>, TB;
4334
4335 // Table lookup instructions
4336
4337 def XLAT : I<0xD7, RawFrm, (outs), (ins), "xlatb", []>;
4338
4339 // Specialized register support
4340
4341 def WRMSR : I<0x30, RawFrm, (outs), (ins), "wrmsr", []>, TB;
4342 def RDMSR : I<0x32, RawFrm, (outs), (ins), "rdmsr", []>, TB;
4343 def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", []>, TB;
4344
4345 def SMSW16r : I<0x01, MRM4r, (outs GR16:$dst), (ins), 
4346                 "smsw{w}\t$dst", []>, OpSize, TB;
4347 def SMSW32r : I<0x01, MRM4r, (outs GR32:$dst), (ins), 
4348                 "smsw{l}\t$dst", []>, TB;
4349 // For memory operands, there is only a 16-bit form
4350 def SMSW16m : I<0x01, MRM4m, (outs i16mem:$dst), (ins),
4351                 "smsw{w}\t$dst", []>, TB;
4352
4353 def LMSW16r : I<0x01, MRM6r, (outs), (ins GR16:$src),
4354                 "lmsw{w}\t$src", []>, TB;
4355 def LMSW16m : I<0x01, MRM6m, (outs), (ins i16mem:$src),
4356                 "lmsw{w}\t$src", []>, TB;
4357                 
4358 def CPUID : I<0xA2, RawFrm, (outs), (ins), "cpuid", []>, TB;
4359
4360 // Cache instructions
4361
4362 def INVD : I<0x08, RawFrm, (outs), (ins), "invd", []>, TB;
4363 def WBINVD : I<0x09, RawFrm, (outs), (ins), "wbinvd", []>, TB;
4364
4365 // VMX instructions
4366
4367 // 66 0F 38 80
4368 def INVEPT : I<0x80, RawFrm, (outs), (ins), "invept", []>, OpSize, T8;
4369 // 66 0F 38 81
4370 def INVVPID : I<0x81, RawFrm, (outs), (ins), "invvpid", []>, OpSize, T8;
4371 // 0F 01 C1
4372 def VMCALL : I<0x01, MRM_C1, (outs), (ins), "vmcall", []>, TB;
4373 def VMCLEARm : I<0xC7, MRM6m, (outs), (ins i64mem:$vmcs),
4374   "vmclear\t$vmcs", []>, OpSize, TB;
4375 // 0F 01 C2
4376 def VMLAUNCH : I<0x01, MRM_C2, (outs), (ins), "vmlaunch", []>, TB;
4377 // 0F 01 C3
4378 def VMRESUME : I<0x01, MRM_C3, (outs), (ins), "vmresume", []>, TB;
4379 def VMPTRLDm : I<0xC7, MRM6m, (outs), (ins i64mem:$vmcs),
4380   "vmptrld\t$vmcs", []>, TB;
4381 def VMPTRSTm : I<0xC7, MRM7m, (outs i64mem:$vmcs), (ins),
4382   "vmptrst\t$vmcs", []>, TB;
4383 def VMREAD64rm : I<0x78, MRMDestMem, (outs i64mem:$dst), (ins GR64:$src),
4384   "vmread{q}\t{$src, $dst|$dst, $src}", []>, TB;
4385 def VMREAD64rr : I<0x78, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
4386   "vmread{q}\t{$src, $dst|$dst, $src}", []>, TB;
4387 def VMREAD32rm : I<0x78, MRMDestMem, (outs i32mem:$dst), (ins GR32:$src),
4388   "vmread{l}\t{$src, $dst|$dst, $src}", []>, TB;
4389 def VMREAD32rr : I<0x78, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
4390   "vmread{l}\t{$src, $dst|$dst, $src}", []>, TB;
4391 def VMWRITE64rm : I<0x79, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
4392   "vmwrite{q}\t{$src, $dst|$dst, $src}", []>, TB;
4393 def VMWRITE64rr : I<0x79, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
4394   "vmwrite{q}\t{$src, $dst|$dst, $src}", []>, TB;
4395 def VMWRITE32rm : I<0x79, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
4396   "vmwrite{l}\t{$src, $dst|$dst, $src}", []>, TB;
4397 def VMWRITE32rr : I<0x79, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
4398   "vmwrite{l}\t{$src, $dst|$dst, $src}", []>, TB;
4399 // 0F 01 C4
4400 def VMXOFF : I<0x01, MRM_C4, (outs), (ins), "vmxoff", []>, TB;
4401 def VMXON : I<0xC7, MRM6m, (outs), (ins i64mem:$vmxon),
4402   "vmxon\t{$vmxon}", []>, XS;
4403
4404 //===----------------------------------------------------------------------===//
4405 // Non-Instruction Patterns
4406 //===----------------------------------------------------------------------===//
4407
4408 // ConstantPool GlobalAddress, ExternalSymbol, and JumpTable
4409 def : Pat<(i32 (X86Wrapper tconstpool  :$dst)), (MOV32ri tconstpool  :$dst)>;
4410 def : Pat<(i32 (X86Wrapper tjumptable  :$dst)), (MOV32ri tjumptable  :$dst)>;
4411 def : Pat<(i32 (X86Wrapper tglobaltlsaddr:$dst)),(MOV32ri tglobaltlsaddr:$dst)>;
4412 def : Pat<(i32 (X86Wrapper tglobaladdr :$dst)), (MOV32ri tglobaladdr :$dst)>;
4413 def : Pat<(i32 (X86Wrapper texternalsym:$dst)), (MOV32ri texternalsym:$dst)>;
4414 def : Pat<(i32 (X86Wrapper tblockaddress:$dst)), (MOV32ri tblockaddress:$dst)>;
4415
4416 def : Pat<(add GR32:$src1, (X86Wrapper tconstpool:$src2)),
4417           (ADD32ri GR32:$src1, tconstpool:$src2)>;
4418 def : Pat<(add GR32:$src1, (X86Wrapper tjumptable:$src2)),
4419           (ADD32ri GR32:$src1, tjumptable:$src2)>;
4420 def : Pat<(add GR32:$src1, (X86Wrapper tglobaladdr :$src2)),
4421           (ADD32ri GR32:$src1, tglobaladdr:$src2)>;
4422 def : Pat<(add GR32:$src1, (X86Wrapper texternalsym:$src2)),
4423           (ADD32ri GR32:$src1, texternalsym:$src2)>;
4424 def : Pat<(add GR32:$src1, (X86Wrapper tblockaddress:$src2)),
4425           (ADD32ri GR32:$src1, tblockaddress:$src2)>;
4426
4427 def : Pat<(store (i32 (X86Wrapper tglobaladdr:$src)), addr:$dst),
4428           (MOV32mi addr:$dst, tglobaladdr:$src)>;
4429 def : Pat<(store (i32 (X86Wrapper texternalsym:$src)), addr:$dst),
4430           (MOV32mi addr:$dst, texternalsym:$src)>;
4431 def : Pat<(store (i32 (X86Wrapper tblockaddress:$src)), addr:$dst),
4432           (MOV32mi addr:$dst, tblockaddress:$src)>;
4433
4434 // Calls
4435 // tailcall stuff
4436 def : Pat<(X86tcret GR32_TC:$dst, imm:$off),
4437           (TCRETURNri GR32_TC:$dst, imm:$off)>,
4438           Requires<[In32BitMode]>;
4439
4440 // FIXME: This is disabled for 32-bit PIC mode because the global base
4441 // register which is part of the address mode may be assigned a 
4442 // callee-saved register.
4443 def : Pat<(X86tcret (load addr:$dst), imm:$off),
4444           (TCRETURNmi addr:$dst, imm:$off)>,
4445           Requires<[In32BitMode, IsNotPIC]>;
4446
4447 def : Pat<(X86tcret (i32 tglobaladdr:$dst), imm:$off),
4448           (TCRETURNdi texternalsym:$dst, imm:$off)>,
4449           Requires<[In32BitMode]>;
4450
4451 def : Pat<(X86tcret (i32 texternalsym:$dst), imm:$off),
4452           (TCRETURNdi texternalsym:$dst, imm:$off)>,
4453           Requires<[In32BitMode]>;
4454
4455 // Normal calls, with various flavors of addresses.
4456 def : Pat<(X86call (i32 tglobaladdr:$dst)),
4457           (CALLpcrel32 tglobaladdr:$dst)>;
4458 def : Pat<(X86call (i32 texternalsym:$dst)),
4459           (CALLpcrel32 texternalsym:$dst)>;
4460 def : Pat<(X86call (i32 imm:$dst)),
4461           (CALLpcrel32 imm:$dst)>, Requires<[CallImmAddr]>;
4462
4463 // X86 specific add which produces a flag.
4464 def : Pat<(addc GR32:$src1, GR32:$src2),
4465           (ADD32rr GR32:$src1, GR32:$src2)>;
4466 def : Pat<(addc GR32:$src1, (load addr:$src2)),
4467           (ADD32rm GR32:$src1, addr:$src2)>;
4468 def : Pat<(addc GR32:$src1, imm:$src2),
4469           (ADD32ri GR32:$src1, imm:$src2)>;
4470 def : Pat<(addc GR32:$src1, i32immSExt8:$src2),
4471           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
4472
4473 def : Pat<(subc GR32:$src1, GR32:$src2),
4474           (SUB32rr GR32:$src1, GR32:$src2)>;
4475 def : Pat<(subc GR32:$src1, (load addr:$src2)),
4476           (SUB32rm GR32:$src1, addr:$src2)>;
4477 def : Pat<(subc GR32:$src1, imm:$src2),
4478           (SUB32ri GR32:$src1, imm:$src2)>;
4479 def : Pat<(subc GR32:$src1, i32immSExt8:$src2),
4480           (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
4481
4482 // Comparisons.
4483
4484 // TEST R,R is smaller than CMP R,0
4485 def : Pat<(X86cmp GR8:$src1, 0),
4486           (TEST8rr GR8:$src1, GR8:$src1)>;
4487 def : Pat<(X86cmp GR16:$src1, 0),
4488           (TEST16rr GR16:$src1, GR16:$src1)>;
4489 def : Pat<(X86cmp GR32:$src1, 0),
4490           (TEST32rr GR32:$src1, GR32:$src1)>;
4491
4492 // Conditional moves with folded loads with operands swapped and conditions
4493 // inverted.
4494 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_B, EFLAGS),
4495           (CMOVAE16rm GR16:$src2, addr:$src1)>;
4496 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_B, EFLAGS),
4497           (CMOVAE32rm GR32:$src2, addr:$src1)>;
4498 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_AE, EFLAGS),
4499           (CMOVB16rm GR16:$src2, addr:$src1)>;
4500 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_AE, EFLAGS),
4501           (CMOVB32rm GR32:$src2, addr:$src1)>;
4502 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_E, EFLAGS),
4503           (CMOVNE16rm GR16:$src2, addr:$src1)>;
4504 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_E, EFLAGS),
4505           (CMOVNE32rm GR32:$src2, addr:$src1)>;
4506 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NE, EFLAGS),
4507           (CMOVE16rm GR16:$src2, addr:$src1)>;
4508 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NE, EFLAGS),
4509           (CMOVE32rm GR32:$src2, addr:$src1)>;
4510 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_BE, EFLAGS),
4511           (CMOVA16rm GR16:$src2, addr:$src1)>;
4512 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_BE, EFLAGS),
4513           (CMOVA32rm GR32:$src2, addr:$src1)>;
4514 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_A, EFLAGS),
4515           (CMOVBE16rm GR16:$src2, addr:$src1)>;
4516 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_A, EFLAGS),
4517           (CMOVBE32rm GR32:$src2, addr:$src1)>;
4518 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_L, EFLAGS),
4519           (CMOVGE16rm GR16:$src2, addr:$src1)>;
4520 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_L, EFLAGS),
4521           (CMOVGE32rm GR32:$src2, addr:$src1)>;
4522 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_GE, EFLAGS),
4523           (CMOVL16rm GR16:$src2, addr:$src1)>;
4524 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_GE, EFLAGS),
4525           (CMOVL32rm GR32:$src2, addr:$src1)>;
4526 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_LE, EFLAGS),
4527           (CMOVG16rm GR16:$src2, addr:$src1)>;
4528 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_LE, EFLAGS),
4529           (CMOVG32rm GR32:$src2, addr:$src1)>;
4530 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_G, EFLAGS),
4531           (CMOVLE16rm GR16:$src2, addr:$src1)>;
4532 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_G, EFLAGS),
4533           (CMOVLE32rm GR32:$src2, addr:$src1)>;
4534 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_P, EFLAGS),
4535           (CMOVNP16rm GR16:$src2, addr:$src1)>;
4536 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_P, EFLAGS),
4537           (CMOVNP32rm GR32:$src2, addr:$src1)>;
4538 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NP, EFLAGS),
4539           (CMOVP16rm GR16:$src2, addr:$src1)>;
4540 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NP, EFLAGS),
4541           (CMOVP32rm GR32:$src2, addr:$src1)>;
4542 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_S, EFLAGS),
4543           (CMOVNS16rm GR16:$src2, addr:$src1)>;
4544 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_S, EFLAGS),
4545           (CMOVNS32rm GR32:$src2, addr:$src1)>;
4546 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NS, EFLAGS),
4547           (CMOVS16rm GR16:$src2, addr:$src1)>;
4548 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NS, EFLAGS),
4549           (CMOVS32rm GR32:$src2, addr:$src1)>;
4550 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_O, EFLAGS),
4551           (CMOVNO16rm GR16:$src2, addr:$src1)>;
4552 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_O, EFLAGS),
4553           (CMOVNO32rm GR32:$src2, addr:$src1)>;
4554 def : Pat<(X86cmov (loadi16 addr:$src1), GR16:$src2, X86_COND_NO, EFLAGS),
4555           (CMOVO16rm GR16:$src2, addr:$src1)>;
4556 def : Pat<(X86cmov (loadi32 addr:$src1), GR32:$src2, X86_COND_NO, EFLAGS),
4557           (CMOVO32rm GR32:$src2, addr:$src1)>;
4558
4559 // zextload bool -> zextload byte
4560 def : Pat<(zextloadi8i1  addr:$src), (MOV8rm     addr:$src)>;
4561 def : Pat<(zextloadi16i1 addr:$src), (MOVZX16rm8 addr:$src)>;
4562 def : Pat<(zextloadi32i1 addr:$src), (MOVZX32rm8 addr:$src)>;
4563
4564 // extload bool -> extload byte
4565 def : Pat<(extloadi8i1 addr:$src),   (MOV8rm      addr:$src)>;
4566 def : Pat<(extloadi16i1 addr:$src),  (MOVZX16rm8  addr:$src)>;
4567 def : Pat<(extloadi32i1 addr:$src),  (MOVZX32rm8  addr:$src)>;
4568 def : Pat<(extloadi16i8 addr:$src),  (MOVZX16rm8  addr:$src)>;
4569 def : Pat<(extloadi32i8 addr:$src),  (MOVZX32rm8  addr:$src)>;
4570 def : Pat<(extloadi32i16 addr:$src), (MOVZX32rm16 addr:$src)>;
4571
4572 // anyext. Define these to do an explicit zero-extend to
4573 // avoid partial-register updates.
4574 def : Pat<(i16 (anyext GR8 :$src)), (MOVZX16rr8  GR8 :$src)>;
4575 def : Pat<(i32 (anyext GR8 :$src)), (MOVZX32rr8  GR8 :$src)>;
4576
4577 // Except for i16 -> i32 since isel expect i16 ops to be promoted to i32.
4578 def : Pat<(i32 (anyext GR16:$src)),
4579           (INSERT_SUBREG (i32 (IMPLICIT_DEF)), GR16:$src, sub_16bit)>;
4580
4581
4582 //===----------------------------------------------------------------------===//
4583 // Some peepholes
4584 //===----------------------------------------------------------------------===//
4585
4586 // Odd encoding trick: -128 fits into an 8-bit immediate field while
4587 // +128 doesn't, so in this special case use a sub instead of an add.
4588 def : Pat<(add GR16:$src1, 128),
4589           (SUB16ri8 GR16:$src1, -128)>;
4590 def : Pat<(store (add (loadi16 addr:$dst), 128), addr:$dst),
4591           (SUB16mi8 addr:$dst, -128)>;
4592 def : Pat<(add GR32:$src1, 128),
4593           (SUB32ri8 GR32:$src1, -128)>;
4594 def : Pat<(store (add (loadi32 addr:$dst), 128), addr:$dst),
4595           (SUB32mi8 addr:$dst, -128)>;
4596
4597 // r & (2^16-1) ==> movz
4598 def : Pat<(and GR32:$src1, 0xffff),
4599           (MOVZX32rr16 (EXTRACT_SUBREG GR32:$src1, sub_16bit))>;
4600 // r & (2^8-1) ==> movz
4601 def : Pat<(and GR32:$src1, 0xff),
4602           (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src1, 
4603                                                              GR32_ABCD)),
4604                                       sub_8bit))>,
4605       Requires<[In32BitMode]>;
4606 // r & (2^8-1) ==> movz
4607 def : Pat<(and GR16:$src1, 0xff),
4608           (MOVZX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src1, 
4609                                                              GR16_ABCD)),
4610                                       sub_8bit))>,
4611       Requires<[In32BitMode]>;
4612
4613 // sext_inreg patterns
4614 def : Pat<(sext_inreg GR32:$src, i16),
4615           (MOVSX32rr16 (EXTRACT_SUBREG GR32:$src, sub_16bit))>;
4616 def : Pat<(sext_inreg GR32:$src, i8),
4617           (MOVSX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
4618                                                              GR32_ABCD)),
4619                                       sub_8bit))>,
4620       Requires<[In32BitMode]>;
4621 def : Pat<(sext_inreg GR16:$src, i8),
4622           (MOVSX16rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
4623                                                              GR16_ABCD)),
4624                                       sub_8bit))>,
4625       Requires<[In32BitMode]>;
4626
4627 // trunc patterns
4628 def : Pat<(i16 (trunc GR32:$src)),
4629           (EXTRACT_SUBREG GR32:$src, sub_16bit)>;
4630 def : Pat<(i8 (trunc GR32:$src)),
4631           (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
4632                           sub_8bit)>,
4633       Requires<[In32BitMode]>;
4634 def : Pat<(i8 (trunc GR16:$src)),
4635           (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
4636                           sub_8bit)>,
4637       Requires<[In32BitMode]>;
4638
4639 // h-register tricks
4640 def : Pat<(i8 (trunc (srl_su GR16:$src, (i8 8)))),
4641           (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
4642                           sub_8bit_hi)>,
4643       Requires<[In32BitMode]>;
4644 def : Pat<(i8 (trunc (srl_su GR32:$src, (i8 8)))),
4645           (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
4646                           sub_8bit_hi)>,
4647       Requires<[In32BitMode]>;
4648 def : Pat<(srl GR16:$src, (i8 8)),
4649           (EXTRACT_SUBREG
4650             (MOVZX32rr8
4651               (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
4652                               sub_8bit_hi)),
4653             sub_16bit)>,
4654       Requires<[In32BitMode]>;
4655 def : Pat<(i32 (zext (srl_su GR16:$src, (i8 8)))),
4656           (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
4657                                                              GR16_ABCD)),
4658                                       sub_8bit_hi))>,
4659       Requires<[In32BitMode]>;
4660 def : Pat<(i32 (anyext (srl_su GR16:$src, (i8 8)))),
4661           (MOVZX32rr8 (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, 
4662                                                              GR16_ABCD)),
4663                                       sub_8bit_hi))>,
4664       Requires<[In32BitMode]>;
4665 def : Pat<(and (srl_su GR32:$src, (i8 8)), (i32 255)),
4666           (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
4667                                                              GR32_ABCD)),
4668                                       sub_8bit_hi))>,
4669       Requires<[In32BitMode]>;
4670 def : Pat<(srl (and_su GR32:$src, 0xff00), (i8 8)),
4671           (MOVZX32rr8 (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, 
4672                                                              GR32_ABCD)),
4673                                       sub_8bit_hi))>,
4674       Requires<[In32BitMode]>;
4675
4676 // (shl x, 1) ==> (add x, x)
4677 def : Pat<(shl GR8 :$src1, (i8 1)), (ADD8rr  GR8 :$src1, GR8 :$src1)>;
4678 def : Pat<(shl GR16:$src1, (i8 1)), (ADD16rr GR16:$src1, GR16:$src1)>;
4679 def : Pat<(shl GR32:$src1, (i8 1)), (ADD32rr GR32:$src1, GR32:$src1)>;
4680
4681 // (shl x (and y, 31)) ==> (shl x, y)
4682 def : Pat<(shl GR8:$src1, (and CL, 31)),
4683           (SHL8rCL GR8:$src1)>;
4684 def : Pat<(shl GR16:$src1, (and CL, 31)),
4685           (SHL16rCL GR16:$src1)>;
4686 def : Pat<(shl GR32:$src1, (and CL, 31)),
4687           (SHL32rCL GR32:$src1)>;
4688 def : Pat<(store (shl (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
4689           (SHL8mCL addr:$dst)>;
4690 def : Pat<(store (shl (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
4691           (SHL16mCL addr:$dst)>;
4692 def : Pat<(store (shl (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
4693           (SHL32mCL addr:$dst)>;
4694
4695 def : Pat<(srl GR8:$src1, (and CL, 31)),
4696           (SHR8rCL GR8:$src1)>;
4697 def : Pat<(srl GR16:$src1, (and CL, 31)),
4698           (SHR16rCL GR16:$src1)>;
4699 def : Pat<(srl GR32:$src1, (and CL, 31)),
4700           (SHR32rCL GR32:$src1)>;
4701 def : Pat<(store (srl (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
4702           (SHR8mCL addr:$dst)>;
4703 def : Pat<(store (srl (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
4704           (SHR16mCL addr:$dst)>;
4705 def : Pat<(store (srl (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
4706           (SHR32mCL addr:$dst)>;
4707
4708 def : Pat<(sra GR8:$src1, (and CL, 31)),
4709           (SAR8rCL GR8:$src1)>;
4710 def : Pat<(sra GR16:$src1, (and CL, 31)),
4711           (SAR16rCL GR16:$src1)>;
4712 def : Pat<(sra GR32:$src1, (and CL, 31)),
4713           (SAR32rCL GR32:$src1)>;
4714 def : Pat<(store (sra (loadi8 addr:$dst), (and CL, 31)), addr:$dst),
4715           (SAR8mCL addr:$dst)>;
4716 def : Pat<(store (sra (loadi16 addr:$dst), (and CL, 31)), addr:$dst),
4717           (SAR16mCL addr:$dst)>;
4718 def : Pat<(store (sra (loadi32 addr:$dst), (and CL, 31)), addr:$dst),
4719           (SAR32mCL addr:$dst)>;
4720
4721 // (anyext (setcc_carry)) -> (setcc_carry)
4722 def : Pat<(i16 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
4723           (SETB_C16r)>;
4724 def : Pat<(i32 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
4725           (SETB_C32r)>;
4726 def : Pat<(i32 (anyext (i16 (X86setcc_c X86_COND_B, EFLAGS)))),
4727           (SETB_C32r)>;
4728
4729 // (or x1, x2) -> (add x1, x2) if two operands are known not to share bits.
4730 let AddedComplexity = 5 in { // Try this before the selecting to OR
4731 def : Pat<(or_is_add GR16:$src1, imm:$src2),
4732           (ADD16ri GR16:$src1, imm:$src2)>;
4733 def : Pat<(or_is_add GR32:$src1, imm:$src2),
4734           (ADD32ri GR32:$src1, imm:$src2)>;
4735 def : Pat<(or_is_add GR16:$src1, i16immSExt8:$src2),
4736           (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
4737 def : Pat<(or_is_add GR32:$src1, i32immSExt8:$src2),
4738           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
4739 def : Pat<(or_is_add GR16:$src1, GR16:$src2),
4740           (ADD16rr GR16:$src1, GR16:$src2)>;
4741 def : Pat<(or_is_add GR32:$src1, GR32:$src2),
4742           (ADD32rr GR32:$src1, GR32:$src2)>;
4743 } // AddedComplexity
4744
4745 //===----------------------------------------------------------------------===//
4746 // EFLAGS-defining Patterns
4747 //===----------------------------------------------------------------------===//
4748
4749 // add reg, reg
4750 def : Pat<(add GR8 :$src1, GR8 :$src2), (ADD8rr  GR8 :$src1, GR8 :$src2)>;
4751 def : Pat<(add GR16:$src1, GR16:$src2), (ADD16rr GR16:$src1, GR16:$src2)>;
4752 def : Pat<(add GR32:$src1, GR32:$src2), (ADD32rr GR32:$src1, GR32:$src2)>;
4753
4754 // add reg, mem
4755 def : Pat<(add GR8:$src1, (loadi8 addr:$src2)),
4756           (ADD8rm GR8:$src1, addr:$src2)>;
4757 def : Pat<(add GR16:$src1, (loadi16 addr:$src2)),
4758           (ADD16rm GR16:$src1, addr:$src2)>;
4759 def : Pat<(add GR32:$src1, (loadi32 addr:$src2)),
4760           (ADD32rm GR32:$src1, addr:$src2)>;
4761
4762 // add reg, imm
4763 def : Pat<(add GR8 :$src1, imm:$src2), (ADD8ri  GR8:$src1 , imm:$src2)>;
4764 def : Pat<(add GR16:$src1, imm:$src2), (ADD16ri GR16:$src1, imm:$src2)>;
4765 def : Pat<(add GR32:$src1, imm:$src2), (ADD32ri GR32:$src1, imm:$src2)>;
4766 def : Pat<(add GR16:$src1, i16immSExt8:$src2),
4767           (ADD16ri8 GR16:$src1, i16immSExt8:$src2)>;
4768 def : Pat<(add GR32:$src1, i32immSExt8:$src2),
4769           (ADD32ri8 GR32:$src1, i32immSExt8:$src2)>;
4770
4771 // sub reg, reg
4772 def : Pat<(sub GR8 :$src1, GR8 :$src2), (SUB8rr  GR8 :$src1, GR8 :$src2)>;
4773 def : Pat<(sub GR16:$src1, GR16:$src2), (SUB16rr GR16:$src1, GR16:$src2)>;
4774 def : Pat<(sub GR32:$src1, GR32:$src2), (SUB32rr GR32:$src1, GR32:$src2)>;
4775
4776 // sub reg, mem
4777 def : Pat<(sub GR8:$src1, (loadi8 addr:$src2)),
4778           (SUB8rm GR8:$src1, addr:$src2)>;
4779 def : Pat<(sub GR16:$src1, (loadi16 addr:$src2)),
4780           (SUB16rm GR16:$src1, addr:$src2)>;
4781 def : Pat<(sub GR32:$src1, (loadi32 addr:$src2)),
4782           (SUB32rm GR32:$src1, addr:$src2)>;
4783
4784 // sub reg, imm
4785 def : Pat<(sub GR8:$src1, imm:$src2),
4786           (SUB8ri GR8:$src1, imm:$src2)>;
4787 def : Pat<(sub GR16:$src1, imm:$src2),
4788           (SUB16ri GR16:$src1, imm:$src2)>;
4789 def : Pat<(sub GR32:$src1, imm:$src2),
4790           (SUB32ri GR32:$src1, imm:$src2)>;
4791 def : Pat<(sub GR16:$src1, i16immSExt8:$src2),
4792           (SUB16ri8 GR16:$src1, i16immSExt8:$src2)>;
4793 def : Pat<(sub GR32:$src1, i32immSExt8:$src2),
4794           (SUB32ri8 GR32:$src1, i32immSExt8:$src2)>;
4795
4796 // mul reg, reg
4797 def : Pat<(mul GR16:$src1, GR16:$src2),
4798           (IMUL16rr GR16:$src1, GR16:$src2)>;
4799 def : Pat<(mul GR32:$src1, GR32:$src2),
4800           (IMUL32rr GR32:$src1, GR32:$src2)>;
4801
4802 // mul reg, mem
4803 def : Pat<(mul GR16:$src1, (loadi16 addr:$src2)),
4804           (IMUL16rm GR16:$src1, addr:$src2)>;
4805 def : Pat<(mul GR32:$src1, (loadi32 addr:$src2)),
4806           (IMUL32rm GR32:$src1, addr:$src2)>;
4807
4808 // mul reg, imm
4809 def : Pat<(mul GR16:$src1, imm:$src2),
4810           (IMUL16rri GR16:$src1, imm:$src2)>;
4811 def : Pat<(mul GR32:$src1, imm:$src2),
4812           (IMUL32rri GR32:$src1, imm:$src2)>;
4813 def : Pat<(mul GR16:$src1, i16immSExt8:$src2),
4814           (IMUL16rri8 GR16:$src1, i16immSExt8:$src2)>;
4815 def : Pat<(mul GR32:$src1, i32immSExt8:$src2),
4816           (IMUL32rri8 GR32:$src1, i32immSExt8:$src2)>;
4817
4818 // reg = mul mem, imm
4819 def : Pat<(mul (loadi16 addr:$src1), imm:$src2),
4820           (IMUL16rmi addr:$src1, imm:$src2)>;
4821 def : Pat<(mul (loadi32 addr:$src1), imm:$src2),
4822           (IMUL32rmi addr:$src1, imm:$src2)>;
4823 def : Pat<(mul (loadi16 addr:$src1), i16immSExt8:$src2),
4824           (IMUL16rmi8 addr:$src1, i16immSExt8:$src2)>;
4825 def : Pat<(mul (loadi32 addr:$src1), i32immSExt8:$src2),
4826           (IMUL32rmi8 addr:$src1, i32immSExt8:$src2)>;
4827
4828 // Optimize multiply by 2 with EFLAGS result.
4829 let AddedComplexity = 2 in {
4830 def : Pat<(X86smul_flag GR16:$src1, 2), (ADD16rr GR16:$src1, GR16:$src1)>;
4831 def : Pat<(X86smul_flag GR32:$src1, 2), (ADD32rr GR32:$src1, GR32:$src1)>;
4832 }
4833
4834 // Patterns for nodes that do not produce flags, for instructions that do.
4835
4836 // Increment reg.
4837 def : Pat<(add GR8:$src1 ,  1), (INC8r  GR8:$src1)>;
4838 def : Pat<(add GR16:$src1,  1), (INC16r GR16:$src1)>, Requires<[In32BitMode]>;
4839 def : Pat<(add GR32:$src1,  1), (INC32r GR32:$src1)>, Requires<[In32BitMode]>;
4840
4841 // Decrement reg.
4842 def : Pat<(add GR8:$src1 , -1), (DEC8r  GR8:$src1)>;
4843 def : Pat<(add GR16:$src1, -1), (DEC16r GR16:$src1)>, Requires<[In32BitMode]>;
4844 def : Pat<(add GR32:$src1, -1), (DEC32r GR32:$src1)>, Requires<[In32BitMode]>;
4845
4846 // or reg/reg.
4847 def : Pat<(or GR8 :$src1, GR8 :$src2), (OR8rr  GR8 :$src1, GR8 :$src2)>;
4848 def : Pat<(or GR16:$src1, GR16:$src2), (OR16rr GR16:$src1, GR16:$src2)>;
4849 def : Pat<(or GR32:$src1, GR32:$src2), (OR32rr GR32:$src1, GR32:$src2)>;
4850
4851 // or reg/mem
4852 def : Pat<(or GR8:$src1, (loadi8 addr:$src2)),
4853           (OR8rm GR8:$src1, addr:$src2)>;
4854 def : Pat<(or GR16:$src1, (loadi16 addr:$src2)),
4855           (OR16rm GR16:$src1, addr:$src2)>;
4856 def : Pat<(or GR32:$src1, (loadi32 addr:$src2)),
4857           (OR32rm GR32:$src1, addr:$src2)>;
4858
4859 // or reg/imm
4860 def : Pat<(or GR8:$src1 , imm:$src2), (OR8ri  GR8 :$src1, imm:$src2)>;
4861 def : Pat<(or GR16:$src1, imm:$src2), (OR16ri GR16:$src1, imm:$src2)>;
4862 def : Pat<(or GR32:$src1, imm:$src2), (OR32ri GR32:$src1, imm:$src2)>;
4863 def : Pat<(or GR16:$src1, i16immSExt8:$src2),
4864           (OR16ri8 GR16:$src1, i16immSExt8:$src2)>;
4865 def : Pat<(or GR32:$src1, i32immSExt8:$src2),
4866           (OR32ri8 GR32:$src1, i32immSExt8:$src2)>;
4867
4868 // xor reg/reg
4869 def : Pat<(xor GR8 :$src1, GR8 :$src2), (XOR8rr  GR8 :$src1, GR8 :$src2)>;
4870 def : Pat<(xor GR16:$src1, GR16:$src2), (XOR16rr GR16:$src1, GR16:$src2)>;
4871 def : Pat<(xor GR32:$src1, GR32:$src2), (XOR32rr GR32:$src1, GR32:$src2)>;
4872
4873 // xor reg/mem
4874 def : Pat<(xor GR8:$src1, (loadi8 addr:$src2)),
4875           (XOR8rm GR8:$src1, addr:$src2)>;
4876 def : Pat<(xor GR16:$src1, (loadi16 addr:$src2)),
4877           (XOR16rm GR16:$src1, addr:$src2)>;
4878 def : Pat<(xor GR32:$src1, (loadi32 addr:$src2)),
4879           (XOR32rm GR32:$src1, addr:$src2)>;
4880
4881 // xor reg/imm
4882 def : Pat<(xor GR8:$src1, imm:$src2),
4883           (XOR8ri GR8:$src1, imm:$src2)>;
4884 def : Pat<(xor GR16:$src1, imm:$src2),
4885           (XOR16ri GR16:$src1, imm:$src2)>;
4886 def : Pat<(xor GR32:$src1, imm:$src2),
4887           (XOR32ri GR32:$src1, imm:$src2)>;
4888 def : Pat<(xor GR16:$src1, i16immSExt8:$src2),
4889           (XOR16ri8 GR16:$src1, i16immSExt8:$src2)>;
4890 def : Pat<(xor GR32:$src1, i32immSExt8:$src2),
4891           (XOR32ri8 GR32:$src1, i32immSExt8:$src2)>;
4892
4893 // and reg/reg
4894 def : Pat<(and GR8 :$src1, GR8 :$src2), (AND8rr  GR8 :$src1, GR8 :$src2)>;
4895 def : Pat<(and GR16:$src1, GR16:$src2), (AND16rr GR16:$src1, GR16:$src2)>;
4896 def : Pat<(and GR32:$src1, GR32:$src2), (AND32rr GR32:$src1, GR32:$src2)>;
4897
4898 // and reg/mem
4899 def : Pat<(and GR8:$src1, (loadi8 addr:$src2)),
4900           (AND8rm GR8:$src1, addr:$src2)>;
4901 def : Pat<(and GR16:$src1, (loadi16 addr:$src2)),
4902           (AND16rm GR16:$src1, addr:$src2)>;
4903 def : Pat<(and GR32:$src1, (loadi32 addr:$src2)),
4904           (AND32rm GR32:$src1, addr:$src2)>;
4905
4906 // and reg/imm
4907 def : Pat<(and GR8:$src1, imm:$src2),
4908           (AND8ri GR8:$src1, imm:$src2)>;
4909 def : Pat<(and GR16:$src1, imm:$src2),
4910           (AND16ri GR16:$src1, imm:$src2)>;
4911 def : Pat<(and GR32:$src1, imm:$src2),
4912           (AND32ri GR32:$src1, imm:$src2)>;
4913 def : Pat<(and GR16:$src1, i16immSExt8:$src2),
4914           (AND16ri8 GR16:$src1, i16immSExt8:$src2)>;
4915 def : Pat<(and GR32:$src1, i32immSExt8:$src2),
4916           (AND32ri8 GR32:$src1, i32immSExt8:$src2)>;
4917
4918 //===----------------------------------------------------------------------===//
4919 // Floating Point Stack Support
4920 //===----------------------------------------------------------------------===//
4921
4922 include "X86InstrFPStack.td"
4923
4924 //===----------------------------------------------------------------------===//
4925 // X86-64 Support
4926 //===----------------------------------------------------------------------===//
4927
4928 include "X86Instr64bit.td"
4929
4930 //===----------------------------------------------------------------------===//
4931 // SIMD support (SSE, MMX and AVX)
4932 //===----------------------------------------------------------------------===//
4933
4934 include "X86InstrFragmentsSIMD.td"
4935
4936 //===----------------------------------------------------------------------===//
4937 // XMM Floating point support (requires SSE / SSE2)
4938 //===----------------------------------------------------------------------===//
4939
4940 include "X86InstrSSE.td"
4941
4942 //===----------------------------------------------------------------------===//
4943 // MMX and XMM Packed Integer support (requires MMX, SSE, and SSE2)
4944 //===----------------------------------------------------------------------===//
4945
4946 include "X86InstrMMX.td"