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