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