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