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