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