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