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