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