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