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