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