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