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