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