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