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